awk: fix mktime() for dates beyond 2038
do_mktime() returned the result of mktime() as int. Since int is
32 bits wide even on LP64 systems, any time at or after
2038-01-19 03:14:08 UTC was truncated, even with a 64-bit time_t:
$ TZ=UTC busybox awk 'BEGIN { printf "%.0f\n", mktime("2038 01 19 03 14 08") }'
-2147483648
Return time_t instead and add a testcase.
function old new delta
exec_builtin 1130 1136 +6
do_mktime 119 121 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 8/0) Total: 8 bytes
Signed-off-by: Michael Pfeifroth <micpf@westermo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
1 parent
3a381903ce
commit
2d6925708e
2 files changed
+8
-1
No files matched your search
+1
-1
@@ -2914,7 +2914,7 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest /*,in
|
|||||||
return match_no;
|
return match_no;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NOINLINE int do_mktime(const char *ds)
|
static NOINLINE time_t do_mktime(const char *ds)
|
||||||
{
|
{
|
||||||
struct tm then;
|
struct tm then;
|
||||||
int count;
|
int count;
|
||||||
|
|||||||
@@ -828,4 +828,11 @@ testing 'awk gensub backslash*8 + & in replacement' 'awk '$sq'{ print gensub(/b
|
|||||||
testing 'awk gensub backslash*10 + & in replacement' 'awk '$sq'{ print gensub(/b/, "_\\\\\\\\\\&_", 1) }'$sq 'a_\\\\&_c\n' '' 'abc\n'
|
testing 'awk gensub backslash*10 + & in replacement' 'awk '$sq'{ print gensub(/b/, "_\\\\\\\\\\&_", 1) }'$sq 'a_\\\\&_c\n' '' 'abc\n'
|
||||||
testing 'awk gensub backslash*12 + & in replacement' 'awk '$sq'{ print gensub(/b/, "_\\\\\\\\\\\\&_", 1) }'$sq 'a_\\\\\\b_c\n' '' 'abc\n'
|
testing 'awk gensub backslash*12 + & in replacement' 'awk '$sq'{ print gensub(/b/, "_\\\\\\\\\\\\&_", 1) }'$sq 'a_\\\\\\b_c\n' '' 'abc\n'
|
||||||
|
|
||||||
|
optional TIME64
|
||||||
|
testing "awk mktime() beyond 2038" \
|
||||||
|
"TZ=UTC awk 'BEGIN { printf \"%.0f %.0f\\n\", mktime(\"2038 01 19 03 14 08\"), mktime(\"2040 01 01 00 00 00\") }'" \
|
||||||
|
"2147483648 2208988800\n" \
|
||||||
|
"" ""
|
||||||
|
SKIP=
|
||||||
|
|
||||||
exit $FAILCOUNT
|
exit $FAILCOUNT
|
||||||
Reference in new issue
Block a user