From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 183883848E35; Tue, 6 Dec 2022 14:00:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 183883848E35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670335254; bh=UWEohZd9QnHdiXWH/nIW8QVPVZpR8041Gil0rv9vF0Y=; h=From:To:Subject:Date:From; b=ExTaHj2N1Zuxpz85DsA0JozfqhxRWY8qOan8CvhVm/bVlDAKzyqm35aQqtX8pfxnn eO7Whg7JGpLl4aA/Y+wsdDn2S3Rwafoncw9VkvYo2bJFSWa6sDAWylnIUfJYGxZRBF srS2CN2zWVu6rpq/ETAs4nki6ugVbvTixT3xrmdo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4507] ada: Add Codepeer Exemption + simplify TO_C code. X-Act-Checkin: gcc X-Git-Author: Liaiss Merzougue X-Git-Refname: refs/heads/master X-Git-Oldrev: ed34c3bc3428bce663d42e9eeda10bc0c5d56d5c X-Git-Newrev: c690f116b64be820cd47a554bffeadd9907fed2a Message-Id: <20221206140054.183883848E35@sourceware.org> Date: Tue, 6 Dec 2022 14:00:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c690f116b64be820cd47a554bffeadd9907fed2a commit r13-4507-gc690f116b64be820cd47a554bffeadd9907fed2a Author: Liaiss Merzougue Date: Fri Apr 2 09:29:03 2021 +0000 ada: Add Codepeer Exemption + simplify TO_C code. This patch simplify the TO_C code to have a single branch for raising exception. Furthermore, adding pragma annotate for codepeer to ignore uninitialized value since this is caused because we have input check before the initialization. gcc/ada/ * libgnat/i-c.adb (To_C): Simplify code for having a single exception raise. Add pragma annotate about uninitialized value which happen only on exception raising. Diff: --- gcc/ada/libgnat/i-c.adb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gcc/ada/libgnat/i-c.adb b/gcc/ada/libgnat/i-c.adb index 4b50d18a5a1..28660219b6e 100644 --- a/gcc/ada/libgnat/i-c.adb +++ b/gcc/ada/libgnat/i-c.adb @@ -186,7 +186,7 @@ is (Item : char_array; Trim_Nul : Boolean := True) return String is - Count : Natural; + Count : Natural := 0; From : size_t; begin @@ -1177,7 +1177,7 @@ is To : size_t; begin - if Target'Length < Item'Length then + if Target'Length < Item'Length + (if Append_Nul then 1 else 0) then raise Constraint_Error; else @@ -1210,17 +1210,14 @@ is Target'First + (Item'Length - 1))'Initialized); if Append_Nul then - if To > Target'Last then - raise Constraint_Error; - else - Target (To) := char32_nul; - Count := Item'Length + 1; - end if; - + Target (To) := char32_nul; + Count := Item'Length + 1; else Count := Item'Length; end if; end if; end To_C; + pragma Annotate (CodePeer, False_Positive, "validity check", + "Count is only uninitialized on abnormal return."); end Interfaces.C;