From b928d57ca9aa7457ec0dee022c1664e8cd606b22 Mon Sep 17 00:00:00 2001 From: Kyle Lippincott Date: Mon, 5 Aug 2024 17:10:07 +0000 Subject: set errno=0 before strtoX calls To detect conversion failure after calls to functions like `strtod`, one can check `errno == ERANGE`. These functions are not guaranteed to set `errno` to `0` on successful conversion, however. Manual manipulation of `errno` can likely be avoided by checking that the output pointer differs from the input pointer, but that's not how other locations, such as parse.c:139, handle this issue; they set errno to 0 prior to executing the function. For every place I could find a strtoX function with an ERANGE check following it, set `errno = 0;` prior to executing the conversion function. Signed-off-by: Kyle Lippincott Signed-off-by: Junio C Hamano --- ref-filter.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ref-filter.c') diff --git a/ref-filter.c b/ref-filter.c index 8c5e673fc0..54880a2497 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1628,6 +1628,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam timestamp = parse_timestamp(eoemail + 2, &zone, 10); if (timestamp == TIME_MAX) goto bad; + errno = 0; tz = strtol(zone, NULL, 10); if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE) goto bad; -- cgit v1.3