On Wed, 27 Jul 2022, Jakub Jelinek wrote:

> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK, I think we can make this a gcc_assert even.

Richard.

> 2022-07-27  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR middle-end/106332
>       * opts-common.cc (candidates_list_and_hint): Add gcc_checking_assert
>       that candidates is not an empty vector.
> 
> --- gcc/opts-common.cc.jj     2022-02-04 14:36:55.439599237 +0100
> +++ gcc/opts-common.cc        2022-07-26 11:21:49.785919993 +0200
> @@ -1347,6 +1347,8 @@ candidates_list_and_hint (const char *ar
>    const char *candidate;
>    char *p;
>  
> +  gcc_checking_assert (!candidates.is_empty ());
> +
>    FOR_EACH_VEC_ELT (candidates, i, candidate)
>      len += strlen (candidate) + 1;
>  
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

Reply via email to