From 20d145efefe2b0ebbca7cf3af5d48c561283dcb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 21 Mar 2018 16:09:08 +0000 Subject: [PATCH] Replace isc_string_touint64 with strtoull (C99) --- lib/dns/rdata/any_255/tsig_250.c | 2 +- lib/isc/include/isc/string.h | 32 ----------- lib/isc/log.c | 5 +- lib/isc/netscope.c | 4 +- lib/isc/string.c | 76 ------------------------- lib/isc/win32/include/isc/platform.h.in | 12 ++++ lib/isc/win32/libisc.def.in | 2 - lib/isccfg/namedconf.c | 4 +- lib/isccfg/parser.c | 2 +- 9 files changed, 21 insertions(+), 118 deletions(-) diff --git a/lib/dns/rdata/any_255/tsig_250.c b/lib/dns/rdata/any_255/tsig_250.c index 9282c073f1..ed68b24919 100644 --- a/lib/dns/rdata/any_255/tsig_250.c +++ b/lib/dns/rdata/any_255/tsig_250.c @@ -52,7 +52,7 @@ fromtext_any_tsig(ARGS_FROMTEXT) { */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); - sigtime = isc_string_touint64(DNS_AS_STR(token), &e, 10); + sigtime = strtoull(DNS_AS_STR(token), &e, 10); if (*e != 0) RETTOK(DNS_R_SYNTAX); if ((sigtime >> 48) != 0) diff --git a/lib/isc/include/isc/string.h b/lib/isc/include/isc/string.h index 43e6af63e1..0c77f87b37 100644 --- a/lib/isc/include/isc/string.h +++ b/lib/isc/include/isc/string.h @@ -32,21 +32,6 @@ ISC_LANG_BEGINDECLS -isc_uint64_t -isc_string_touint64(char *source, char **endp, int base); -/*%< - * Convert the string pointed to by 'source' to isc_uint64_t. - * - * On successful conversion 'endp' points to the first character - * after conversion is complete. - * - * 'base': 0 or 2..36 - * - * If base is 0 the base is computed from the string type. - * - * On error 'endp' points to 'source'. - */ - isc_result_t isc_string_copy(char *target, size_t size, const char *source); /* @@ -114,23 +99,6 @@ isc_string_append(char *target, size_t size, const char *source); * is too small. */ -void -isc_string_append_truncate(char *target, size_t size, const char *source); -/* - * Append the string pointed to by 'source' to 'target' which is a - * pointer to a NUL terminated string of at least 'size' bytes. - * - * Requires: - * 'target' is a pointer to a NUL terminated char[] of at - * least 'size' bytes. - * 'size' an integer > 0. - * 'source' == NULL or points to a NUL terminated string. - * - * Ensures: - * 'target' will be a NUL terminated string of no more - * than 'size' bytes (including NUL). - */ - isc_result_t isc_string_printf(char *target, size_t size, const char *format, ...) ISC_FORMAT_PRINTF(3, 4); diff --git a/lib/isc/log.c b/lib/isc/log.c index 224e6653ce..98c0ed45dd 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -1280,8 +1280,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) { dir.entry.name[bnamelen] == '.') { char *ename = &dir.entry.name[bnamelen + 1]; - version = isc_string_touint64(ename, - &digit_end, 10); + version = strtoull(ename, &digit_end, 10); if (*digit_end == '\0') { int i = 0; while (i < versions && @@ -1316,7 +1315,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) { dir.entry.name[bnamelen] == '.') { char *ename = &dir.entry.name[bnamelen + 1]; - version = isc_string_touint64(ename, &digit_end, 10); + version = strtoull(ename, &digit_end, 10); /* * Remove any backup files that exceed versions. */ diff --git a/lib/isc/netscope.c b/lib/isc/netscope.c index 85a25b6f13..859d05ff68 100644 --- a/lib/isc/netscope.c +++ b/lib/isc/netscope.c @@ -13,6 +13,8 @@ #include +#include + #include #include #include @@ -47,7 +49,7 @@ isc_netscope_pton(int af, char *scopename, void *addr, isc_uint32_t *zoneid) { zone = (isc_uint32_t)ifid; else { #endif - llz = isc_string_touint64(scopename, &ep, 10); + llz = strtoull(scopename, &ep, 10); if (ep == scopename) return (ISC_R_FAILURE); diff --git a/lib/isc/string.c b/lib/isc/string.c index eab78c20b0..a9e5d40aa6 100644 --- a/lib/isc/string.c +++ b/lib/isc/string.c @@ -50,72 +50,6 @@ #include #include -static const char digits[] = "0123456789abcdefghijklmnoprstuvwxyz"; - -isc_uint64_t -isc_string_touint64(char *source, char **end, int base) { - isc_uint64_t tmp; - isc_uint64_t overflow; - char *s = source; - const char *o; - char c; - - if ((base < 0) || (base == 1) || (base > 36)) { - *end = source; - return (0); - } - - while (*s != 0 && isascii(*s&0xff) && isspace(*s&0xff)) - s++; - if (*s == '+' /* || *s == '-' */) - s++; - if (base == 0) { - if (*s == '0' && (*(s+1) == 'X' || *(s+1) == 'x')) { - s += 2; - base = 16; - } else if (*s == '0') - base = 8; - else - base = 10; - } - if (*s == 0) { - *end = source; - return (0); - } - overflow = ~0; - overflow /= base; - tmp = 0; - - while ((c = *s) != 0) { - c = tolower(c&0xff); - /* end ? */ - if ((o = strchr(digits, c)) == NULL) { - *end = s; - return (tmp); - } - /* end ? */ - if ((o - digits) >= base) { - *end = s; - return (tmp); - } - /* overflow ? */ - if (tmp > overflow) { - *end = source; - return (0); - } - tmp *= base; - /* overflow ? */ - if ((tmp + (o - digits)) < tmp) { - *end = source; - return (0); - } - tmp += o - digits; - s++; - } - *end = s; - return (tmp); -} - isc_result_t isc_string_copy(char *target, size_t size, const char *source) { REQUIRE(size > 0U); @@ -154,16 +88,6 @@ isc_string_append(char *target, size_t size, const char *source) { return (ISC_R_SUCCESS); } -void -isc_string_append_truncate(char *target, size_t size, const char *source) { - REQUIRE(size > 0U); - REQUIRE(strlen(target) < size); - - strlcat(target, source, size); - - ENSURE(strlen(target) < size); -} - isc_result_t isc_string_printf(char *target, size_t size, const char *format, ...) { va_list args; diff --git a/lib/isc/win32/include/isc/platform.h.in b/lib/isc/win32/include/isc/platform.h.in index 3da8f37c33..e3f534f7b8 100644 --- a/lib/isc/win32/include/isc/platform.h.in +++ b/lib/isc/win32/include/isc/platform.h.in @@ -20,6 +20,18 @@ #define ISC_PLATFORM_USETHREADS 1 +/* + * Some compatibility cludges + */ + +#if defined(_WIN32) || defined(_WIN64) + +#ifndef strtoull +#define strtoull _strtoui64 +#endif + +#endif + /*** *** Network. ***/ diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 66a44a54be..85beac7e69 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -646,7 +646,6 @@ isc_stdio_tell isc_stdio_write isc_stdtime_get isc_string_append -isc_string_append_truncate isc_string_copy isc_string_copy_truncate isc_string_printf @@ -656,7 +655,6 @@ isc_string_separate isc_string_strcasestr isc_string_strlcat isc_string_strlcpy -isc_string_touint64 isc_symtab_count isc_symtab_create isc_symtab_define diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index c3cab304e9..7bd6fce625 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -2552,7 +2552,7 @@ parse_unitstring(char *str, isc_resourcevalue_t *valuep) { isc_uint64_t value; isc_uint64_t unit; - value = isc_string_touint64(str, &endp, 10); + value = strtoull(str, &endp, 10); if (*endp == 0) { *valuep = value; return (ISC_R_SUCCESS); @@ -2628,7 +2628,7 @@ parse_sizeval_percent(cfg_parser_t *pctx, const cfg_type_t *type, goto cleanup; } - percent = isc_string_touint64(TOKEN_STRING(pctx), &endp, 10); + percent = strtoull(TOKEN_STRING(pctx), &endp, 10); if (*endp == '%' && *(endp+1) == 0) { CHECK(cfg_create_obj(pctx, &cfg_type_percentage, &obj)); diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index ef6a92da48..6e840161fb 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -752,7 +752,7 @@ cfg_parse_percentage(cfg_parser_t *pctx, const cfg_type_t *type, return (ISC_R_UNEXPECTEDTOKEN); } - percent = isc_string_touint64(TOKEN_STRING(pctx), &endp, 10); + percent = strtoull(TOKEN_STRING(pctx), &endp, 10); if (*endp != '%' || *(endp+1) != 0) { cfg_parser_error(pctx, CFG_LOG_NEAR, "expected percentage");