summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-05-24 20:33:27 +0200
committerJim Meyering <meyering@redhat.com>2011-05-25 08:25:54 +0200
commitdac67b8cc244c796a771565457939371b0b7b035 (patch)
treec7bbae7fbad42c8aa3b688e2e15efa6fd5266b7c
parent7d44751f0ea9d353c14edffbf89dc61dcafa8f22 (diff)
downloadcoreutils-dac67b8cc244c796a771565457939371b0b7b035.tar.xz
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
-rw-r--r--src/touch.c18
1 files 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++;