Nmap Development mailing list archives
[PATCH] Use UCHAR_MAX and USHRT_MAX in genfry()
From: Kris Katterjohn <kjak () ispwest com>
Date: Thu, 09 Mar 2006 12:01:36 -0600
The attached patch uses UCHAR_MAX and USHRT_MAX instead of 256 and 65536. It also changes some 'x = *y; y++;' to 'x = *y++;'. Thanks, Kris
--- utils.cc.orig 2006-03-09 11:32:46.000000000 -0600 +++ utils.cc 2006-03-09 11:55:44.000000000 -0600 @@ -99,6 +99,7 @@ /* $Id: utils.cc 3200 2006-03-05 23:59:46Z fyodor $ */ +#include <limits.h> #include "utils.h" #include "NmapOps.h" @@ -305,11 +306,12 @@ if (num_elem < 2) } /* OK, so I am stingy with the random bytes! */ -if (num_elem < 256) +if (num_elem <= UCHAR_MAX) bpe = sizeof(unsigned char); -else if (num_elem < 65536) +else if (num_elem <= USHRT_MAX) bpe = sizeof(unsigned short); -else bpe = sizeof(unsigned int); +else + bpe = sizeof(unsigned int); bytes = (unsigned char *) malloc(bpe * num_elem); tmp = (unsigned char *) malloc(elem_sz); @@ -320,14 +322,12 @@ sptr = (unsigned short *)bytes; iptr = (unsigned int *) bytes; for(i=num_elem - 1; i > 0; i--) { - if (num_elem < 256) { - pos = *cptr; cptr++; - } - else if (num_elem < 65536) { - pos = *sptr; sptr++; - } else { - pos = *iptr; iptr++; - } + if (num_elem <= UCHAR_MAX) + pos = *cptr++; + else if (num_elem <= USHRT_MAX) + pos = *sptr++; + else + pos = *iptr++; pos %= i+1; memcpy(tmp, arr + elem_sz * i, elem_sz); memcpy(arr + elem_sz * i, arr + elem_sz * pos, elem_sz);
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev
Current thread:
- [PATCH] Use UCHAR_MAX and USHRT_MAX in genfry() Kris Katterjohn (Mar 09)