Cast arg_max to size_t when comparing it (times 4, plus 1) against SIZE_MAX. I

was worried about truncation of arg_max by this cast, but if it gets truncated,
we know it'll obviously be greater than SIZE_MAX anyway.

Big pointy hat to:	jmallett
Submitted by:		keramida
This commit is contained in:
Juli Mallett 2002-06-06 20:29:39 +00:00
parent 033340171a
commit 3d0d5dccc1

View File

@ -70,7 +70,8 @@ shquote(char **argv)
if (buf == NULL) { if (buf == NULL) {
if ((arg_max = sysconf(_SC_ARG_MAX)) == -1) if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
errx(1, "sysconf _SC_ARG_MAX failed"); errx(1, "sysconf _SC_ARG_MAX failed");
if (arg_max >= LONG_MAX / 4 || 4 * arg_max + 1 > SIZE_MAX) if (arg_max >= LONG_MAX / 4 ||
4 * (size_t)arg_max + 1 > SIZE_MAX)
errx(1, "sysconf _SC_ARG_MAX preposterously large"); errx(1, "sysconf _SC_ARG_MAX preposterously large");
buf_size = 4 * arg_max + 1; buf_size = 4 * arg_max + 1;
if ((buf = malloc(buf_size)) == NULL) if ((buf = malloc(buf_size)) == NULL)