From patchwork Fri Jun 23 20:37:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tulio Magno Quites Machado Filho X-Patchwork-Id: 21244 X-Patchwork-Delegate: fweimer@redhat.com Received: (qmail 21611 invoked by alias); 23 Jun 2017 20:38:59 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21561 invoked by uid 89); 23 Jun 2017 20:38:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=complement X-HELO: mx0a-001b2d01.pphosted.com From: "Tulio Magno Quites Machado Filho" To: libc-alpha@sourceware.org Cc: fweimer@redhat.com Subject: [PATCH] Prevent an implicit int promotion in malloc/tst-alloc_buffer.c Date: Fri, 23 Jun 2017 17:37:36 -0300 X-TM-AS-MML: disable x-cbid: 17062320-0032-0000-0000-0000056D6542 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062320-0033-0000-0000-000011F3B91A Message-Id: <20170623203736.16876-1-tuliom@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-23_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706230347 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 * 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); }