summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-10-16 23:35:08 +0300
committerLinus Groh <mail@linusgroh.de>2022-10-17 01:08:22 +0200
commitdb45e242c45ac4317156bfc86a1b1715f6109503 (patch)
tree9c2c387c22eb19286b770db455ddd6a47033fc2b /Userland/Libraries/LibC
parent711f64d3667522cfd59264ba1e15d9c4776683a7 (diff)
downloadserenity-db45e242c45ac4317156bfc86a1b1715f6109503.zip
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.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/stdio.cpp7
1 files changed, 5 insertions, 2 deletions
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<int>(ch & 0xff);
+ }
return EOF;
}