static analyzer bit

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';
}
This commit is contained in:
PatR
2018-02-17 18:54:52 -08:00
parent 544b9015ff
commit 48af4fa259

View 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++;