summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2022-02-08 01:16:48 +0100
committerBruno Haible <bruno@clisp.org>2022-02-08 01:16:48 +0100
commitd89cab871231a82c0783ce520d692f08a32f2da6 (patch)
treecfbebfe047aee488b5f0fe98f8b2c0652c27e505
parent6d53a2dbe0ad692d0f36fd394b7e1962d9a81730 (diff)
downloadgperf-d89cab871231a82c0783ce520d692f08a32f2da6.tar.gz
tests: Fix undefined behaviour.
* tests/test2.c (main): Cast bytes to unsigned before shifting left.
-rw-r--r--ChangeLog5
-rw-r--r--tests/test2.c2
2 files changed, 6 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1667552..6c9d1d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-02-07 Bruno Haible <bruno@clisp.org>
+
+ tests: Fix undefined behaviour.
+ * tests/test2.c (main): Cast bytes to unsigned before shifting left.
+
2022-01-05 Bruno Haible <bruno@clisp.org>
Release gperf-3.2.
diff --git a/tests/test2.c b/tests/test2.c
index c1c08cc..ecd3d18 100644
--- a/tests/test2.c
+++ b/tests/test2.c
@@ -45,7 +45,7 @@ main (int argc, char *argv[])
char *p = buf;
while (fread (p, 2, 1, stdin) == 1)
{
- if ((p[0] << 8) + p[1] == '\n')
+ if (((unsigned char) p[0] << 8) + (unsigned char) p[1] == '\n')
break;
p += 2;
}