sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 8d96afd4fb266688e8f55db978d5bc9b3c380ca6
parent d89cd4811898a183f629323b855d1b5623c2da5e
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 15 Apr 2016 20:44:32 +0200

touch: make invalid date an error and fix uninitialised value

reproduce: touch -t 12345678 mytralala

would only give a warning and use uninitialised time values. The proper
way is to treat it as an error. Clear the "struct tm" and kill some lines
just in case.

Diffstat:
Mtouch.c | 7++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/touch.c b/touch.c @@ -48,7 +48,7 @@ touch(const char *file) static time_t parsetime(char *str, time_t current) { - struct tm *cur, t; + struct tm *cur, t = { 0 }; int zulu = 0; char *format; size_t len = strlen(str); @@ -59,12 +59,10 @@ parsetime(char *str, time_t current) switch (len) { /* -t flag argument */ case 8: - t.tm_sec = 0; t.tm_year = cur->tm_year; format = "%m%d%H%M"; break; case 10: - t.tm_sec = 0; format = "%y%m%d%H%M"; break; case 11: @@ -72,7 +70,6 @@ parsetime(char *str, time_t current) format = "%m%d%H%M.%S"; break; case 12: - t.tm_sec = 0; format = "%Y%m%d%H%M"; break; case 13: @@ -98,7 +95,7 @@ parsetime(char *str, time_t current) } if (!strptime(str, format, &t)) - weprintf("strptime %s: Invalid date format\n", str); + eprintf("strptime %s: Invalid date format\n", str); if (zulu) { t.tm_hour += t.tm_gmtoff / 60; t.tm_gmtoff = 0;