summaryrefslogtreecommitdiff
path: root/gpxlogger.c
diff options
context:
space:
mode:
authorBernhard Übelacker <bernhardu@mailbox.org>2018-09-18 15:53:08 +0200
committerGary E. Miller <gem@rellim.com>2018-10-02 15:09:27 -0700
commita41bd6c329032492571049e5e2453976a55c8760 (patch)
tree3285482747516052a6cb795d4f1863945e59abd2 /gpxlogger.c
parentf55f07151a4af607c6fcae4193e784d92da89f2e (diff)
downloadgpsd-a41bd6c329032492571049e5e2453976a55c8760.tar.gz
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 <gem@rellim.com>
Diffstat (limited to 'gpxlogger.c')
-rw-r--r--gpxlogger.c8
1 files 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");