rewrite comparison to avoid negative unsigned numbers

Note that GCC -O2 is happy to optimize away (x<0) when x is an
unsigned quantity.  This was actually occurring in CHECKLEN(0),
causing the compiler to issue a warning.
This commit is contained in:
Barak A. Pearlmutter 2014-04-02 12:52:32 +01:00 committed by Erik Ekman
parent ee1c49a383
commit f73fb9f8d0
1 changed files with 2 additions and 2 deletions

View File

@ -45,7 +45,7 @@
int dnsc_use_edns0 = 1;
#define CHECKLEN(x) if (buflen - (p-buf) < (x)) return 0
#define CHECKLEN(x) if (buflen < (x) + (unsigned)(p-buf)) return 0
int
dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_t datalen)
@ -391,7 +391,7 @@ dns_get_id(char *packet, size_t packetlen)
return ntohs(header->id);
}
#define CHECKLEN(x) if (packetlen - (data-packet) < (x)) return 0
#define CHECKLEN(x) if (packetlen < (x) + (unsigned)(data-packet)) return 0
int
dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, size_t packetlen)