sbase

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

commit 3dc8e30e9219ae530917195d08da2a43830bafc5
parent a2e4beca400f76e9e4777a94e31ed704cef0b6f8
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri Apr 15 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:
touch.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;