From a41bd6c329032492571049e5e2453976a55c8760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= Date: Tue, 18 Sep 2018 15:53:08 +0200 Subject: gpxlogger: Move buffer extension below the strftime call. Bug-Debian: https://bugs.debian.org/909082 Last-Update: 2018-09-18 Signed-off-by: Gary E. Miller --- gpxlogger.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gpxlogger.c b/gpxlogger.c index 0a99aee2..9bb60bf4 100644 --- a/gpxlogger.c +++ b/gpxlogger.c @@ -233,7 +233,7 @@ int main(int argc, char **argv) char *fname = NULL; time_t t; size_t s = 0; - size_t fnamesize = strlen(optarg); + size_t fnamesize = strlen(optarg) + 1; t = time(NULL); while (s == 0) { @@ -242,10 +242,14 @@ int main(int argc, char **argv) syslog(LOG_ERR, "realloc failed."); goto bailout; } else { - fnamesize += 1024; fname = newfname; } s = strftime(fname, fnamesize-1, optarg, localtime(&t)); + if (!s) { + /* expanded filename did not fit in string, try + * a bigger string */ + fnamesize += 1024; + } } fname[s] = '\0';; logfile = fopen(fname, "w"); -- cgit v1.2.1