Fix CID 1393540 (Explicit null dereferenced)

Coverity Scan does not like incrementing of a null pointer,
so increment an index value instead of a pointer.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-06-20 17:32:02 +02:00
parent c8dd4456e0
commit d6391ee811

View File

@ -475,20 +475,22 @@ static int tvfscanf(FILE* stream, const char *format, va_list ap) {
if (!(flags & FL_SPLAT)) {
sarg = va_arg(ap, char *);
}
char *sp = sarg;
unsigned length = 0;
while (width--) {
q = fgetc(stream);
if (isspace(static_cast<unsigned char>(q)) || q <= 0) {
ungetc(q, stream);
break;
}
if (!(flags & FL_SPLAT)) *sp = q;
sp++;
if (!(flags & FL_SPLAT)) {
sarg[length] = q;
}
if (sarg == sp) {
length++;
}
if (length == 0) {
bail = BAIL_EOF;
} else if (!(flags & FL_SPLAT)) {
*sp = '\0'; // Terminate output
sarg[length] = '\0'; // Terminate output
converted++;
}
}