[Bug c/106939] Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Sep 14 05:38:14 GMT 2022


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---

#include <string.h>

extern char _src[], _dst[]; // Defined by the linker

int main(void) {
  char *l_src = src;
  char *l_dst = dst;
  asm ("" : "+r" (l_src));
  asm ("" : "+r" (l_dst));
    memcpy(l_src, l_dst + 1024, 1111);
    return 0;
}

--- CUT ---
Well this works too because you are not comparing the start and ends:
#include <string.h>

extern char _src[], _dst[]; // Defined by the linker

int main(void) {
    memcpy(&_dst[0], &_src[0] + 1024, 1111);
    return 0;
}
----- CUT ---
Basically this is a C question really as _src/_dst is only size of 1 in the
original code you provided while in the above two cases it is an unknown size.


More information about the Gcc-bugs mailing list