mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-23 02:55:15 +00:00
LibC: Do an explicit static_cast in the fgetc function
We assumed that by returning a char in the fgetc function that an implicit cast is sufficient, but apparently if that char contains 0xff, the result int will be -1 (0xFFFFFFFF). To ensure this does not happen, let's do an explicit casting.
This commit is contained in:
parent
711f64d366
commit
db45e242c4
|
@ -633,8 +633,11 @@ int fgetc(FILE* stream)
|
|||
VERIFY(stream);
|
||||
char ch;
|
||||
size_t nread = fread(&ch, sizeof(char), 1, stream);
|
||||
if (nread == 1)
|
||||
return ch;
|
||||
if (nread == 1) {
|
||||
// Note: We do this static_cast because otherwise when casting a char that contains
|
||||
// 0xFF results in an int containing -1, so an explicit cast is required here.
|
||||
return static_cast<int>(ch & 0xff);
|
||||
}
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue