wahern / dns

dns.c: Single file non-blocking DNS C library without callbacks or external dependencies.
http://25thandclement.com/~william/projects/dns.c.html
MIT License
256 stars 64 forks source link

-Werror=array-bounds #37

Open raymondjclark opened 3 years ago

raymondjclark commented 3 years ago

Encountering 6 errors while attempting to compile.

til/dns.c:6528:17: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds] so->query->data[-2] = 0xff & (so->query->end >> 8);


util/dns.c:6529:17: error: array subscript -1 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
  so->query->data[-1] = 0xff & (so->query->end >> 0);
  ~~~~~~~~~~~~~~~^~~~
util/dns.c:6531:9: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
  qsrc = &so->query->data[-2] + so->qout;
         ^~~~~~~~~~~~~~~~~~~~
util/dns.c:6557:10: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
   asrc = &so->answer->data[-2];
          ^~~~~~~~~~~~~~~~~~~~~
util/dns.c:6568:18: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
    alen = ((0xff & so->answer->data[-2]) << 8)
            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
util/dns.c:6569:42: error: array subscript -1 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
         | ((0xff & so->answer->data[-1]) << 0);
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~