Skip to content

Commit e03d2a9

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89a0c5c commit e03d2a9

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

Diff for: t/helper/test-csprng.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
#define DISABLE_SIGN_COMPARE_WARNINGS
2-
31
#include "test-tool.h"
42
#include "git-compat-util.h"
53

6-
74
int cmd__csprng(int argc, const char **argv)
85
{
96
unsigned long count;
@@ -14,7 +11,7 @@ int cmd__csprng(int argc, const char **argv)
1411
return 2;
1512
}
1613

17-
count = (argc == 2) ? strtoul(argv[1], NULL, 0) : -1L;
14+
count = (argc == 2) ? strtoul(argv[1], NULL, 0) : ULONG_MAX;
1815

1916
while (count) {
2017
unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf);

Diff for: t/helper/test-genrandom.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
55
*/
66

7-
#define DISABLE_SIGN_COMPARE_WARNINGS
8-
97
#include "test-tool.h"
108
#include "git-compat-util.h"
119

@@ -24,7 +22,7 @@ int cmd__genrandom(int argc, const char **argv)
2422
next = next * 11 + *c;
2523
} while (*c++);
2624

27-
count = (argc == 3) ? strtoul(argv[2], NULL, 0) : -1L;
25+
count = (argc == 3) ? strtoul(argv[2], NULL, 0) : ULONG_MAX;
2826

2927
while (count--) {
3028
next = next * 1103515245 + 12345;

0 commit comments

Comments
 (0)