From: Jim Meyering Date: Tue, 24 May 2011 18:33:27 +0000 (+0200) Subject: touch: placate static analyzers: no NULL-deref is possible X-Git-Tag: v8.13~155 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dac67b8cc244c796a771565457939371b0b7b035;p=thirdparty%2Fcoreutils.git touch: placate static analyzers: no NULL-deref is possible * src/touch.c (main): Avoid even the hint of possibility that we'd dereference NULL upon localtime failure. Coverity reported the potential, but it appears not to be possible, since posixtime rejects any time for which the subsequent localtime would return NULL. See http://thread.gmane.org/gmane.comp.gnu.coreutils.general/1253 --- diff --git a/src/touch.c b/src/touch.c index 49be961e48..18f81c8aa8 100644 --- a/src/touch.c +++ b/src/touch.c @@ -405,12 +405,18 @@ main (int argc, char **argv) if (! getenv ("POSIXLY_CORRECT")) { struct tm const *tm = localtime (&newtime[0].tv_sec); - error (0, 0, - _("warning: `touch %s' is obsolete; use " - "`touch -t %04ld%02d%02d%02d%02d.%02d'"), - argv[optind], - tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); + + /* Technically, it appears that even a deliberate attempt to cause + the above localtime to return NULL will always fail because our + posixtime implementation rejects all dates for which localtime + would fail. However, skip the warning if it ever fails. */ + if (tm) + error (0, 0, + _("warning: `touch %s' is obsolete; use " + "`touch -t %04ld%02d%02d%02d%02d.%02d'"), + argv[optind], + tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); } optind++;