1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

LibC: Fix bug in scanf() family where we'd capture invalid data.

This commit is contained in:
Andreas Kling 2019-03-20 15:29:04 +01:00
parent 951377e93e
commit cdb82f6fbb
3 changed files with 54 additions and 50 deletions

View file

@ -424,5 +424,41 @@ int remove(const char* pathname)
return rmdir(pathname);
}
int scanf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int count = vfscanf(stdin, fmt, ap);
va_end(ap);
return count;
}
int fscanf(FILE* stream, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int count = vfscanf(stream, fmt, ap);
va_end(ap);
return count;
}
int sscanf(const char* buffer, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int count = vsscanf(buffer, fmt, ap);
va_end(ap);
return count;
}
int vfscanf(FILE* stream, const char* fmt, va_list ap)
{
char buffer[BUFSIZ];
if (!fgets(buffer, sizeof(buffer) - 1, stream))
return -1;
return vsscanf(buffer, fmt, ap);
}
}