Skip to content

Commit d6391ee

Browse files
committed
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>
1 parent c8dd445 commit d6391ee

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/ccutil/scanutils.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,22 @@ static int tvfscanf(FILE* stream, const char *format, va_list ap) {
475475
if (!(flags & FL_SPLAT)) {
476476
sarg = va_arg(ap, char *);
477477
}
478-
char *sp = sarg;
478+
unsigned length = 0;
479479
while (width--) {
480480
q = fgetc(stream);
481481
if (isspace(static_cast<unsigned char>(q)) || q <= 0) {
482482
ungetc(q, stream);
483483
break;
484484
}
485-
if (!(flags & FL_SPLAT)) *sp = q;
486-
sp++;
485+
if (!(flags & FL_SPLAT)) {
486+
sarg[length] = q;
487+
}
488+
length++;
487489
}
488-
if (sarg == sp) {
490+
if (length == 0) {
489491
bail = BAIL_EOF;
490492
} else if (!(flags & FL_SPLAT)) {
491-
*sp = '\0'; // Terminate output
493+
sarg[length] = '\0'; // Terminate output
492494
converted++;
493495
}
494496
}

0 commit comments

Comments
 (0)