From dac67b8cc244c796a771565457939371b0b7b035 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 24 May 2011 20:33:27 +0200 Subject: 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 --- src/touch.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/touch.c b/src/touch.c index 49be961e4..18f81c8aa 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++; -- cgit v1.2.3-54-g00ecf