# HG changeset patch # User Matt Johnston # Date 1170496694 0 # Node ID a588558bfc948d6173ca29c960f8fda49c00dff3 # Parent 75940fef22dd9a80934653c5d3dca8ed1c475412 Fix potential null pointer dereference found by Klokwork diff -r 75940fef22dd -r a588558bfc94 svr-session.c --- a/svr-session.c Sat Feb 03 09:42:22 2007 +0000 +++ b/svr-session.c Sat Feb 03 09:58:14 2007 +0000 @@ -181,10 +181,15 @@ if (!svr_opts.usingsyslog || havetrace) { + struct tm * local_tm = NULL; timesec = time(NULL); - if (strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S", - localtime(×ec)) == 0) { - datestr[0] = '?'; datestr[1] = '\0'; + local_tm = localtime(×ec); + if (local_tm == NULL + || strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S", + localtime(×ec)) == 0) + { + // upon failure, just print the epoch-seconds time. + snprintf(datestr, sizeof(datestr), "%d", timesec); } fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf); }