]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
opts: Add an assertion to help static analyzers [PR106332]
authorJakub Jelinek <jakub@redhat.com>
Wed, 27 Jul 2022 10:04:50 +0000 (12:04 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 27 Jul 2022 10:04:50 +0000 (12:04 +0200)
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  <jakub@redhat.com>

PR middle-end/106332
* opts-common.cc (candidates_list_and_hint): Add gcc_assert
that candidates is not an empty vector.

gcc/opts-common.cc

index 1663be1f602a29d43f21fd6f0ed21269e90e8d10..8097c058c729a4b206b35652ca7ccbeb8d8ec9da 100644 (file)
@@ -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;