public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1855] opts: Add an assertion to help static analyzers [PR106332]
@ 2022-07-27 10:05 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-07-27 10:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:cc078cf85295ec5d0a63a16afbd045efac0d455e

commit r13-1855-gcc078cf85295ec5d0a63a16afbd045efac0d455e
Author: Jakub Jelinek <jakub@redhat.com>
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  <jakub@redhat.com>
    
            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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-27 10:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 10:05 [gcc r13-1855] opts: Add an assertion to help static analyzers [PR106332] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).