diff --git a/Userland/Libraries/LibC/stdio.cpp b/Userland/Libraries/LibC/stdio.cpp index 5f609f2c38..a4d372e6d0 100644 --- a/Userland/Libraries/LibC/stdio.cpp +++ b/Userland/Libraries/LibC/stdio.cpp @@ -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(ch & 0xff); + } return EOF; }