* Joseph Myers:

> The real question is how to achieve optimal warnings in the absence of the 
> attribute.  Should we have a variant of the nonnull attribute that warns 
> for NULL arguments but without optimizing based on them?

I think attribute access already covers part of it:

#include <stddef.h>
void read_array (void *, size_t) __attribute__ ((access (read_only, 1, 2)));
void
f (void)
{
  read_array (NULL, 0); // No warning.
  read_array (NULL, 1); // Warning.
}

It does not work for functions like strndup that support both string
arguments (of any length) and array arguments of a specified size.
The read_only variant requires an initialized array of the specified
length.

Reply via email to