Skip to content

Commit 819f0e7

Browse files
peffgitster
authored andcommitted
argv-array: use size_t for count and alloc
On most 64-bit platforms, "int" is significantly smaller than a size_t, which could lead to integer overflow and under-allocation of the array. It's probably impossible to trigger in practice, as it would imply on the order of 2^32 individual allocations. Even if was possible to grow an array in that way (and we typically only use it for sets of strings, like command line options), each allocation needs a pointer, malloc overhead, etc. You'd quite likely run out of RAM before succeeding in such an overflow. But all that hand-waving aside, it's easy enough to use the correct type, so let's do so. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47ae905 commit 819f0e7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

argv-array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ extern const char *empty_argv[];
2929
*/
3030
struct argv_array {
3131
const char **argv;
32-
int argc;
33-
int alloc;
32+
size_t argc;
33+
size_t alloc;
3434
};
3535

3636
#define ARGV_ARRAY_INIT { empty_argv, 0, 0 }

0 commit comments

Comments
 (0)