diff options
Diffstat (limited to 'contrib/ntp/libntp/atouint.c')
-rw-r--r-- | contrib/ntp/libntp/atouint.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/contrib/ntp/libntp/atouint.c b/contrib/ntp/libntp/atouint.c index c25e3a0c51a7..0a6163907a51 100644 --- a/contrib/ntp/libntp/atouint.c +++ b/contrib/ntp/libntp/atouint.c @@ -1,33 +1,40 @@ -/* - * atouint - convert an ascii string to an unsigned long, with error checking - */ +#include <config.h> #include <sys/types.h> #include <ctype.h> #include "ntp_types.h" #include "ntp_stdlib.h" +/* + * atouint() - convert an ascii string representing a whole base 10 + * number to u_long *uval, returning TRUE if successful. + * Does not modify *uval and returns FALSE if str is not + * a positive base10 integer or is too large for a u_int32. + * this function uses u_long but should use u_int32, and + * probably be renamed. + */ int atouint( const char *str, u_long *uval ) { - register u_long u; - register const char *cp; + u_long u; + const char *cp; cp = str; - if (*cp == '\0') - return 0; + if ('\0' == *cp) + return 0; u = 0; - while (*cp != '\0') { - if (!isdigit((int)*cp)) - return 0; + while ('\0' != *cp) { + if (!isdigit((unsigned char)*cp)) + return 0; if (u > 429496729 || (u == 429496729 && *cp >= '6')) - return 0; /* overflow */ + return 0; /* overflow */ + /* hand-optimized u *= 10; */ u = (u << 3) + (u << 1); - u += *cp++ - '0'; /* ascii dependent */ + u += *cp++ - '0'; /* not '\0' */ } *uval = u; |