[PATCH] less.c: width/prec arguments to printf must be type int

Rich Felker dalias at aerifal.cx
Fri May 19 05:02:21 UTC 2006


posix requires regoff_t to be able to hold the largest value that can
fit in either off_t or ssize_t. thus using regoff_t for a printf
format specifier's width or precision is wrong and will lead to
crashes on a compliant implementation with 32bit int and 64bit
size_t/off_t.

rich

-------------- next part --------------
Index: miscutils/less.c
===================================================================
--- miscutils/less.c	(revision 15108)
+++ miscutils/less.c	(working copy)
@@ -626,10 +626,10 @@
 			match_found = 1;
 		
 		if (action) {
-			growline = bb_xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL); 
+			growline = bb_xasprintf("%s%.*s%s%.*s%s", growline, (int)match_structs.rm_so, line2, HIGHLIGHT, (int)(match_structs.rm_eo - match_structs.rm_so), line2 + match_structs.rm_so, NORMAL); 
 		}
 		else {
-			growline = bb_xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
+			growline = bb_xasprintf("%s%.*s%.*s", growline, (int)match_structs.rm_so - 4, line2, (int)(match_structs.rm_eo - match_structs.rm_so), line2 + match_structs.rm_so);
 		}
 		
 		line2 += match_structs.rm_eo;


More information about the busybox mailing list