t/helper: don't depend on implicit wraparound
In our test helpers we have two cases where we assign -1 to an `unsigned long`. The intent is to essentially mean "unbounded output", which is achieved via implicit wraparound of the value. This pattern causes warnings with -Wsign-compare though. Adapt it and instead use `ULONG_MAX` explicitly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 6, 2024 at 11:27 UTC
e03d2a9ccb88c7ff42237f5890a05e071497f8ae
2 files changed
+2
-7
t/helper/test-csprng.c
+1
-4
@@ -1,9 +1,6 @@
1
-#define DISABLE_SIGN_COMPARE_WARNINGS
2
-
1
#include "test-tool.h"
2
#include "git-compat-util.h"
3
6
-
4
int cmd__csprng(int argc, const char **argv)
5
{
6
unsigned long count;
@@ -14,7 +11,7 @@ int cmd__csprng(int argc, const char **argv)
11
return 2;
12
}
13
17
- count = (argc == 2) ? strtoul(argv[1], NULL, 0) : -1L;
14
+ count = (argc == 2) ? strtoul(argv[1], NULL, 0) : ULONG_MAX;
15
16
while (count) {
17
unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf);
t/helper/test-genrandom.c
+1
-3
@@ -4,8 +4,6 @@
4
* Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
5
*/
6
7
-#define DISABLE_SIGN_COMPARE_WARNINGS
8
-
7
#include "test-tool.h"
8
#include "git-compat-util.h"
9
@@ -24,7 +22,7 @@ int cmd__genrandom(int argc, const char **argv)
22
next = next * 11 + *c;
23
} while (*c++);
24
27
- count = (argc == 3) ? strtoul(argv[2], NULL, 0) : -1L;
25
+ count = (argc == 3) ? strtoul(argv[2], NULL, 0) : ULONG_MAX;
26
27
while (count--) {
28
next = next * 1103515245 + 12345;