From 92132b2984184791936f91f0bec0e69247dc34ee Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Fri, 14 Feb 2020 10:24:01 +0000 Subject: [PATCH] base: Use a int to store fgetc return value The stdio fgetc returns the character read as an unsigned char cast to an int. The reason why it gets casted from unsigned char to int is because EOF is defined as a negative value (usually -1). At the moment in the atomicio.test we store the int in a char. However the C standard states that the sign of a char is implementation specific. This makes the test non portable: an architecture/ABI which which is considering a char as a unsigned char won't compile since a unsigned value will always be != -1 (EOF). This is the error message you would get on a aarch64 host /w gcc/5.4.0 build/ARM/base/atomicio.test.cc:121:48: error: comparison is always true due to limited range of data type [-Werror=type-limits] Change-Id: I120e44b5204d98e643f19b8dd6fa2762342a6e64 Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25384 Reviewed-by: Ciro Santilli Reviewed-by: Jason Lowe-Power Tested-by: kokoro --- src/base/atomicio.test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/atomicio.test.cc b/src/base/atomicio.test.cc index 29dacaccb..1801d2cba 100644 --- a/src/base/atomicio.test.cc +++ b/src/base/atomicio.test.cc @@ -115,9 +115,9 @@ TEST(AtomicioTest, AtomicWrite) EXPECT_EQ(file_contents.size(), size); - char c; + int c; for (unsigned int i = 0; (c = fgetc(file)) != EOF; i++) { - EXPECT_EQ(file_contents[i], c); + EXPECT_EQ(file_contents[i], (unsigned char)c); } fclose(file); -- 2.30.2