static analyzer bit
authorPatR <rankin@nethack.org>
Sun, 18 Feb 2018 02:54:52 +0000 (18:54 -0800)
committerPatR <rankin@nethack.org>
Sun, 18 Feb 2018 02:54:52 +0000 (18:54 -0800)
I can't find the original message at the moment, but one of the things
that an analyzer complained about was the *s='\0' possibly assigning
to a Null pointer.  The superfluous test of 's' in the while condition
has fooled it into thinking that's possible when it's not.

if (s) {
  while (s && ...) {
    *s++ = ...
  }
  *s = '\0';
}

src/hacklib.c

index a5d9d0c15d97829e2324ac1a33356a56c71fb145..38255182220364840302f2830efd29d2b0759ecd 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 hacklib.c       $NHDT-Date: 1496860756 2017/06/07 18:39:16 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.50 $ */
+/* NetHack 3.6 hacklib.c       $NHDT-Date: 1518922474 2018/02/18 02:54:34 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.54 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* Copyright (c) Robert Patrick Rankin, 1991                      */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -451,7 +451,7 @@ const char *stuff_to_strip, *orig;
     char *s = bp;
 
     if (s) {
-        while (s && *orig && i < (BUFSZ - 1)) {
+        while (*orig && i < (BUFSZ - 1)) {
             if (!index(stuff_to_strip, *orig)) {
                 *s++ = *orig;
                 i++;