Tue Apr 16 18:33:47 2024 UTC (23d)
Pull up following revision(s) (requested by riastradh in ticket #648):

	lib/libc/time/strptime.c: revision 1.66

strptime(3): Declare digit d as time_t.

This doesn't make a semantic difference -- d can only take on the ten
values {0,1,2,3,4,5,6,7,8,9}, and the arithmetic with it later all
comes out the same whether the type is unsigned or time_t, even if
time_t were int32_t instead of int64_t.

But it pacifies overzealous compilers used by downstream users of
this code.  And while it's silly to use a much wider type (64-bit
signed) than is needed here to store a single digit, it doesn't
really hurt either (32-bit unsigned is much larger than needed too).

PR lib/58041


(martin)
diff -r1.63.6.1 -r1.63.6.2 src/lib/libc/time/strptime.c

cvs diff -r1.63.6.1 -r1.63.6.2 src/lib/libc/time/strptime.c (expand / switch to unified diff)

--- src/lib/libc/time/strptime.c 2024/03/25 14:43:30 1.63.6.1
+++ src/lib/libc/time/strptime.c 2024/04/16 18:33:47 1.63.6.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: strptime.c,v 1.63.6.1 2024/03/25 14:43:30 martin Exp $ */ 1/* $NetBSD: strptime.c,v 1.63.6.2 2024/04/16 18:33:47 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code was contributed to The NetBSD Foundation by Klaus Klein. 7 * This code was contributed to The NetBSD Foundation by Klaus Klein.
8 * Heavily optimised by David Laight 8 * Heavily optimised by David Laight
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34__RCSID("$NetBSD: strptime.c,v 1.63.6.1 2024/03/25 14:43:30 martin Exp $"); 34__RCSID("$NetBSD: strptime.c,v 1.63.6.2 2024/04/16 18:33:47 martin Exp $");
35#endif 35#endif
36 36
37#include "namespace.h" 37#include "namespace.h"
38#include <sys/localedef.h> 38#include <sys/localedef.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <ctype.h> 40#include <ctype.h>
41#include <locale.h> 41#include <locale.h>
42#include <string.h> 42#include <string.h>
43#include <time.h> 43#include <time.h>
44#include <tzfile.h> 44#include <tzfile.h>
45#include "private.h" 45#include "private.h"
46#include "setlocale_local.h" 46#include "setlocale_local.h"
47 47
@@ -338,28 +338,27 @@ literal: @@ -338,28 +338,27 @@ literal:
338 if (HAVE_HOUR(state) && tm->tm_hour > 11) 338 if (HAVE_HOUR(state) && tm->tm_hour > 11)
339 return NULL; 339 return NULL;
340 tm->tm_hour += i * 12; 340 tm->tm_hour += i * 12;
341 LEGAL_ALT(0); 341 LEGAL_ALT(0);
342 continue; 342 continue;
343 343
344 case 'S': /* The seconds. */ 344 case 'S': /* The seconds. */
345 bp = conv_num(bp, &tm->tm_sec, 0, 61); 345 bp = conv_num(bp, &tm->tm_sec, 0, 61);
346 LEGAL_ALT(ALT_O); 346 LEGAL_ALT(ALT_O);
347 continue; 347 continue;
348 348
349 case 's': { /* seconds since the epoch */ 349 case 's': { /* seconds since the epoch */
350 const time_t TIME_MAX = __type_max(time_t); 350 const time_t TIME_MAX = __type_max(time_t);
351 time_t sse; 351 time_t sse, d;
352 unsigned d; 
353 352
354 if (*bp < '0' || *bp > '9') { 353 if (*bp < '0' || *bp > '9') {
355 bp = NULL; 354 bp = NULL;
356 continue; 355 continue;
357 } 356 }
358 357
359 sse = *bp++ - '0'; 358 sse = *bp++ - '0';
360 while (*bp >= '0' && *bp <= '9') { 359 while (*bp >= '0' && *bp <= '9') {
361 d = *bp++ - '0'; 360 d = *bp++ - '0';
362 if (sse > TIME_MAX/10) { 361 if (sse > TIME_MAX/10) {
363 bp = NULL; 362 bp = NULL;
364 break; 363 break;
365 } 364 }