[SLOF] [PATCH] libc: Remove dead code in print_itoa()

Thomas Huth thuth at redhat.com
Sat Nov 28 05:00:50 AEDT 2015


When compiling SLOF with "-Wextra", GCC complains about this:

libc/stdio/vsnprintf.c: In function ‘print_itoa’:
lib/libc/stdio/vsnprintf.c:33:2: warning: comparison of unsigned
                        expression < 0 is always false [-Wtype-limits]
  if(value < 0) {
  ^

When looking more closely at the code, it seems like this is not
only dead code, but even wrong code, since the sign is already
handled in print_format()! So let's simply remove that dead code.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 lib/libc/stdio/vsnprintf.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index e78fb3d..47ba34d 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -25,22 +25,11 @@ static int
 print_itoa(char **buffer,unsigned long value, unsigned short int base)
 {
 	const char zeichen[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
-	static char sign = 0;
 
 	if(base <= 2 || base > 16)
 		return 0;
 
-	if(value < 0) {
-		sign = 1;
-		value *= -1;
-	}
-
 	if(value < base) {
-		if(sign) {
-			**buffer = '-';
-			*buffer += 1;
-			sign = 0;
-		}
 		**buffer = zeichen[value];
 		*buffer += 1;
 	} else {
-- 
1.8.3.1



More information about the SLOF mailing list