svn commit: r226359 - head/usr.bin/look

Ed Schouten ed at 80386.nl
Sun Oct 16 18:20:34 UTC 2011


* Colin Percival <cperciva at freebsd.org>, 20111016 19:21:
> This might make look(1) build, but on a 64-bit machine it also makes
> look(1) fail with "File too large" whenever it's larger than
> (int64_t)(UINT64_MAX) = -1 bytes long.

d'oh! Stupid signedness. I casted to off_t explicitly, since we need to
do 64-bit comparison, but off_t is signed, while size_t is not.

Hmmm... Casting to size_t is not the way to go, but off_t also should be
avoided. We can assume st_size is non-negative, so we should do
something like this, right?

%%%
Index: look.c
===================================================================
--- look.c	(revision 226430)
+++ look.c	(working copy)
@@ -134,7 +134,7 @@
 	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);
%%%

-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/svn-src-all/attachments/20111016/db42b40d/attachment.pgp


More information about the svn-src-all mailing list