Greg Troxel <[email protected]> writes:

> I have long found it funny that the only related warning I've ever heard
> is due to gcc and the NetBSD ctype implementation.  It's a macro (as is
> allowed):
>
>   #define isspace(c)      ((int)((_ctype_tab_ + 1)[(c)] & _CTYPE_S))
>
> which is very efficient when the input is EOF or 0..255.  Well, it's
> efficient regardless, reading random memory.  But it takes advantage of
> the UB leeway in the spec to avoid extra operations.

I meant to say: the warning is "array subscript of type char".  Which is
either because char could be (usually is) "signed char", or because char
isn't a good kind of int for arrays.  gcc has no built-in clue about
ctype functios; it's warning on the inlined code, correctly and
helpfully but somewhat inscrutably.

Coverity ought to do better.  I have never been clear on whether
coverity aims to find UB/etc. in the sources, or if it is looking for UB
in the sources as built on a particular system.

I just ran on Debian 13 amd64:

#include <ctype.h>

  int
  main(){
    int c = -1 * 1024 * 1024;
    int r;

    r = isalpha(c);
    return r;
  }

which got me a segfault.  So it's not bounds checking.  Which is allowed
and not a glibc bug!

Reply via email to