[AD] if-testing for array

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I gave gcc-4.2.0-prerelease a try over allegro code and it reported two valid warnings. It says that the address of an array will always evaluate as 'true'. The attached patch fixes the two cases.

In exkeys example I just removed the test for "str" because ustrzncpy() guarantees that the destination will be null-terminated, thus textprintf_ex will just print a empty string.


--
Milan Mimica
http://sparklet.sf.net
Index: tests/test.c
===================================================================
--- tests/test.c	(revision 7542)
+++ tests/test.c	(working copy)
@@ -4539,7 +4539,7 @@
    #if defined ALLEGRO_I386 || defined ALLEGRO_AMD64
 
       #ifdef ALLEGRO_I386
-         sprintf(cpu_specs, "CPU family: %d86 (%s)", cpu_family, cpu_vendor?cpu_vendor:"unknown");
+         sprintf(cpu_specs, "CPU family: %d86 (%s)", cpu_family, ustrlen(cpu_vendor)?cpu_vendor:"unknown");
       #else
          sprintf(cpu_specs, "CPU family: AMD64 (%s)", cpu_vendor);
       #endif
Index: examples/exkeys.c
===================================================================
--- examples/exkeys.c	(revision 7542)
+++ examples/exkeys.c	(working copy)
@@ -72,9 +72,7 @@
    color = scancode & 0x80 ? makecol (255, 255, 0) : makecol (128, 0, 0);
    rectfill (screen, x, y, x + 95, y + 8, color);
    ustrzncpy (str, sizeof str, scancode_to_name (i), 12);
-   if (str)
-      textprintf_ex (screen, font, x + 1, y + 1, makecol (0, 0, 0), -1,
-	 "%s", str);
+   textprintf_ex (screen, font, x + 1, y + 1, makecol (0, 0, 0), -1, "%s", str);
 }
 END_OF_FUNCTION(keypress_handler)
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/