]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: remove unnecessary size check [cppcheck]
authorSami Kerola <kerolasa@iki.fi>
Sat, 18 May 2019 20:46:08 +0000 (21:46 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 18 May 2019 21:07:20 +0000 (22:07 +0100)
Following warning is false positive.  Size of the buffer is defined using
BUFSIZ, and so the strncpy() will never overwrite the last byte that is
initialized to zero in get_user_reply().

[disk-utils/sfdisk.c:137] -> [disk-utils/sfdisk.c:136]: (warning) Either the
condition 'bufsz!=0' is redundant or strncpy() argument nr 3 can have
invalid value.  The value is -1 but the valid values are '0:'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/sfdisk.c

index 4a9640d0e37cafc5522a03ae2b8a7d76e83a89ed..83f3cf8f7afb337b4342b0def212036d5c02c18f 100644 (file)
@@ -134,8 +134,6 @@ static int get_user_reply(const char *prompt, char *buf, size_t bufsz)
                if (!p)
                        return 1;
                strncpy(buf, p, bufsz - 1);
-               if (bufsz != 0)
-                       buf[bufsz - 1] = '\0';
                free(p);
        } else
 #endif