From d2ea3bed5240d1fb6c1111ef6d49afa088a14588 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sun, 16 Oct 2011 19:15:25 +0000 Subject: [PATCH] Don't cast SIZE_T_MAX to off_t. I focused so much on the 32-bits case where we have to cast SIZE_T_MAX up in size, that I forgot about the 64-bits case, where off_t and size_t are equal in size. Simply cast both numbers to uintmax_t, as we can assume st_size is never negative. Reported by: cperciva --- usr.bin/look/look.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/look/look.c b/usr.bin/look/look.c index ac6082e6ff15..0088864c81ca 100644 --- a/usr.bin/look/look.c +++ b/usr.bin/look/look.c @@ -134,7 +134,7 @@ main(int argc, char *argv[]) do { if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb)) err(2, "%s", file); - if (sb.st_size > (off_t)SIZE_T_MAX) + if ((uintmax_t)sb.st_size > (uintmax_t)SIZE_T_MAX) errx(2, "%s: %s", file, strerror(EFBIG)); if (sb.st_size == 0) { close(fd);