diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2012-01-11 03:43:37 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2012-01-11 03:43:37 -0500 |
commit | e77e8d55373cb639c8ffd6f3d1119c76e8b6f7a7 (patch) | |
tree | 1c845f50cfe321bb84b69ddfdc45feb020091eed /gpxlogger.c | |
parent | b21de406e74835f5f1c513efcc59957bbec31cee (diff) | |
download | gpsd-e77e8d55373cb639c8ffd6f3d1119c76e8b6f7a7.tar.gz |
Fix glitch found by cppcheck.
Diffstat (limited to 'gpxlogger.c')
-rw-r--r-- | gpxlogger.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/gpxlogger.c b/gpxlogger.c index 411b8915..ff252515 100644 --- a/gpxlogger.c +++ b/gpxlogger.c @@ -241,18 +241,24 @@ int main(int argc, char **argv) t = time(NULL); while (s == 0) { - fnamesize += 1024; - fname = realloc(fname, fnamesize); - assert(fname != NULL); /* pacify splint */ - s = strftime(fname, fnamesize - 1, optarg, localtime(&t)); + char *newfname = realloc(fname, fnamesize); + if (newfname == NULL) { + syslog(LOG_ERR, "realloc failed."); + goto bailout; + } else { + fnamesize += 1024; + fname = newfname; + } + s = strftime(fname, fnamesize-1, optarg, localtime(&t)); } assert(fname != NULL); /* pacify splint */ fname[s] = '\0';; logfile = fopen(fname, "w"); if (logfile == NULL) - syslog(LOG_ERR, - "Failed to open %s: %s, logging to stdout.", - fname, strerror(errno)); + syslog(LOG_ERR, + "Failed to open %s: %s, logging to stdout.", + fname, strerror(errno)); + bailout: free(fname); break; } |