From 8f1be1d0db978b5da2fb9a84f9228397af5b5f6f Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 01 Sep 2021 11:57:53 -0400 Subject: main: Skip empty formats This was previously done in _datetime_strftime() but in a way that would overflow the array if an empty format was at the end. Moving this logic into the caller is safer and makes a little more sense. --- diff --git a/src/main.c b/src/main.c index 8e5d2f7..10630e8 100644 --- a/src/main.c +++ b/src/main.c @@ -94,18 +94,27 @@ _list_formats(void) puts("Time formats:"); i = 0; while (datetime_strftime_time(tm, &out, &buf_sz, &buf, &i) > 0) { + if (out[0] == '\0') { + continue; + } printf(" * %s\n", out); } puts("Date formats:"); i = 0; while (datetime_strftime_date(tm, &out, &buf_sz, &buf, &i) > 0) { + if (out[0] == '\0') { + continue; + } printf(" * %s\n", out); } puts("Additional formats:"); i = 0; while (datetime_strftime_misc(tm, &out, &buf_sz, &buf, &i) > 0) { + if (out[0] == '\0') { + continue; + } printf(" * %s\n", out); } } -- cgit v0.9.1