This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Prevent an implicit int promotion in malloc/tst-alloc_buffer.c
- From: "Tulio Magno Quites Machado Filho" <tuliom at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Cc: fweimer at redhat dot com
- Date: Fri, 23 Jun 2017 17:37:36 -0300
- Subject: [PATCH] Prevent an implicit int promotion in malloc/tst-alloc_buffer.c
- Authentication-results: sourceware.org; auth=none
According to ISO C11, section 6.5.3.3 "Unary arithmetic operators", the
result of the ~ operator is the bitwise complement of its (promoted)
operand.
This can lead to a comparison of a char with another integer type.
Tested on powerpc, powerpc64 and powerpc64le.
2017-06-23 Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
* malloc/tst-alloc_buffer.c (test_misaligned): Cast to char
before comparing with another char.
---
malloc/tst-alloc_buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/malloc/tst-alloc_buffer.c b/malloc/tst-alloc_buffer.c
index 1c14399..9b2bd20 100644
--- a/malloc/tst-alloc_buffer.c
+++ b/malloc/tst-alloc_buffer.c
@@ -429,7 +429,7 @@ test_misaligned (char pad)
}
/* Verify that padding was not overwritten. */
- TEST_VERIFY (backing[0] == ~pad);
+ TEST_VERIFY (backing[0] == (char) ~pad);
TEST_VERIFY (backing[SIZE + 1] == pad);
free (backing);
}
--
2.9.4