https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78817

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Looking at the gengtype.c case, I think it is quite common case.
static inline const char*
get_input_file_name (const input_file *inpf)
{
  if (inpf)
      return inpf->inpname;
  return NULL;
}

const char *
get_file_srcdir_relative_path (const input_file *inpf)
{
  const char *f = get_input_file_name (inpf);
  if (strlen (f) > srcdir_len

Of course, if somebody calls get_file_srcdir_relative_path with NULL argument,
it will mean UB in strlen, but that still does not mean that strlen is ever
called with NULL.  The conditional in the first function might be just because
it is used in multiple places, in some where it allows NULL arguments, in
others where it doesn't.
Warning about if you ever hit this spot in the source, it will be always UB is
sometimes useful.  But that is not the case here, the same source location is
represented by 2 or more calls and it is just one of those that the optimizers
can't prove is unreachable, but the user can know is impossible.  Strlen would
segfault anyway if it was ever true.

Reply via email to