From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 037603857001; Wed, 27 Jul 2022 10:05:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 037603857001 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1855] opts: Add an assertion to help static analyzers [PR106332] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 0bc1566dec0cab9410723c96d2ef3280fdab8e8e X-Git-Newrev: cc078cf85295ec5d0a63a16afbd045efac0d455e Message-Id: <20220727100534.037603857001@sourceware.org> Date: Wed, 27 Jul 2022 10:05:34 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jul 2022 10:05:34 -0000 https://gcc.gnu.org/g:cc078cf85295ec5d0a63a16afbd045efac0d455e commit r13-1855-gcc078cf85295ec5d0a63a16afbd045efac0d455e Author: Jakub Jelinek Date: Wed Jul 27 12:04:50 2022 +0200 opts: Add an assertion to help static analyzers [PR106332] This function would have UB if called with empty candidates vector (accessing p[-1] where p is malloc (0) result). As analyzed in the PR, we never call it with empty vector, so this just adds an assertion to make it clear. 2022-07-27 Jakub Jelinek PR middle-end/106332 * opts-common.cc (candidates_list_and_hint): Add gcc_assert that candidates is not an empty vector. Diff: --- gcc/opts-common.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index 1663be1f602..8097c058c72 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -1347,6 +1347,8 @@ candidates_list_and_hint (const char *arg, char *&str, const char *candidate; char *p; + gcc_assert (!candidates.is_empty ()); + FOR_EACH_VEC_ELT (candidates, i, candidate) len += strlen (candidate) + 1;