From 0c8608f81bec2028d2f752f44ae37ef05d02271b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 18 Dec 2017 07:20:02 +0000 Subject: [PATCH] added the endptr parameter to various string to number conversion functions --- qse/cmd/awk/awk.c | 4 +- qse/cmd/http/httpd.c | 6 +- qse/cmd/http/ursd.c | 2 +- qse/cmd/sed/sed.c | 4 +- qse/cmd/xli/xli.c | 4 +- qse/include/qse/cmn/str.h | 374 ++++++++++++++++++++++++------------- qse/lib/cmn/str-cnv.c | 200 +++++++++++++------- qse/lib/http/httpd-cgi.c | 3 +- qse/lib/http/httpd-proxy.c | 2 +- qse/lib/rad/raddic.c | 31 +-- qse/lib/si/nwif-cfg.c | 4 +- qse/lib/si/sinfo.c | 6 +- 12 files changed, 415 insertions(+), 225 deletions(-) diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index ce09fc47..1a08162d 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -637,7 +637,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg) case QSE_T('m'): { - arg->memlimit = qse_strtoulong (opt.arg, 10); + arg->memlimit = qse_strtoulong (opt.arg, 10, QSE_NULL); break; } @@ -650,7 +650,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg) #if defined(QSE_BUILD_DEBUG) case QSE_T('X'): { - arg->failmalloc = qse_strtoulong (opt.arg, 10); + arg->failmalloc = qse_strtoulong (opt.arg, 10, QSE_NULL); break; } #endif diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index 15a34e8f..42c84415 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -1188,7 +1188,7 @@ static int get_intercept (const qse_xli_str_t* v) static int get_integer (const qse_xli_str_t* v) { /* TODO: be more strict */ - return qse_strxtoi (v->ptr, v->len, 10); + return qse_strxtoi (v->ptr, v->len, 10, QSE_NULL); } static int parse_dns_query_types (qse_httpd_t* httpd, const qse_xli_str_t* str) @@ -2046,7 +2046,7 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l else { unsigned int v; - v = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr, 10); + v = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr, 10, QSE_NULL); if (v <= 0) v = 256; dope.backlog_size = v; } @@ -2409,7 +2409,7 @@ static void set_limit (qse_httpd_t* httpd, const qse_char_t* name, int what) if (qse_strxcmp (str, len, QSE_T("unlimited")) == 0) lim.rlim_cur = RLIM_INFINITY; else - lim.rlim_cur = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr, 10); + lim.rlim_cur = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr, 10, QSE_NULL); if (setrlimit (what, &lim) <= -1) { /* TODO: warning */ diff --git a/qse/cmd/http/ursd.c b/qse/cmd/http/ursd.c index e08d4183..0104cb96 100644 --- a/qse/cmd/http/ursd.c +++ b/qse/cmd/http/ursd.c @@ -963,7 +963,7 @@ static int httpd_main (int argc, qse_char_t* argv[]) signal (SIGPIPE, SIG_IGN); #endif - if (init_ursd (&ursd, qse_strtoi(argv[2], 10), argv[1], argv[3]) <= -1) goto oops; + if (init_ursd (&ursd, qse_strtoi(argv[2], 10, QSE_NULL), argv[1], argv[3]) <= -1) goto oops; ursd_inited = 1; while (!g_stop_requested) diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index 96300fde..96a7bcd1 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -362,7 +362,7 @@ static int handle_args (int argc, qse_char_t* argv[]) #endif case QSE_T('m'): - g_memlimit = qse_strtoulong (opt.arg, 10); + g_memlimit = qse_strtoulong (opt.arg, 10, QSE_NULL); break; case QSE_T('w'): @@ -371,7 +371,7 @@ static int handle_args (int argc, qse_char_t* argv[]) #if defined(QSE_BUILD_DEBUG) case QSE_T('X'): - g_failmalloc = qse_strtoulong (opt.arg, 10); + g_failmalloc = qse_strtoulong (opt.arg, 10, QSE_NULL); break; #endif diff --git a/qse/cmd/xli/xli.c b/qse/cmd/xli/xli.c index 1df658a7..bbb77d8f 100644 --- a/qse/cmd/xli/xli.c +++ b/qse/cmd/xli/xli.c @@ -296,12 +296,12 @@ static int handle_args (int argc, qse_char_t* argv[]) break; case QSE_T('m'): - g_memlimit = qse_strtoulong (opt.arg, 10); + g_memlimit = qse_strtoulong (opt.arg, 10, QSE_NULL); break; #if defined(QSE_BUILD_DEBUG) case QSE_T('X'): - g_failmalloc = qse_strtoulong (opt.arg, 10); + g_failmalloc = qse_strtoulong (opt.arg, 10, QSE_NULL); break; #endif diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 85e46f1b..f543e405 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -167,7 +167,7 @@ typedef qse_wchar_t* (*qse_wcssubst_t) ( (c>=QSE_T('a') && c<=QSE_T('z'))? ((c-QSE_T('a')+10=QSE_MT('a') && c<=QSE_MT('z'))? ((c-QSE_MT('a')+10=QSE_WT('a') && c<=QSE_WT('z'))? ((c-QSE_WT('a')+10attr.status, &endptr, 10); + /*QSE_MBSTONUM (nstatus, req->attr.status, &endptr, 10);*/ + nstatus = qse_mbstoi (req->attr.status, 10, &endptr); /* Would it need this kind of extra work? diff --git a/qse/lib/http/httpd-proxy.c b/qse/lib/http/httpd-proxy.c index 7fcca121..7d4f49d8 100644 --- a/qse/lib/http/httpd-proxy.c +++ b/qse/lib/http/httpd-proxy.c @@ -927,7 +927,7 @@ static void adjust_peer_name_and_port (task_proxy_t* proxy) { /* handle a port number after the colon sign */ *colon = QSE_MT('\0'); - proxy->peer_port = qse_mbstoui (colon + 1, 10); + proxy->peer_port = qse_mbstoui (colon + 1, 10, QSE_NULL); /* TODO: check if there is a garbage after the port number. * check if the port number has overflown */ } diff --git a/qse/lib/rad/raddic.c b/qse/lib/rad/raddic.c index 3acbe705..f2661fc8 100644 --- a/qse/lib/rad/raddic.c +++ b/qse/lib/rad/raddic.c @@ -1227,7 +1227,7 @@ static int sscanf_i (qse_raddic_t* dic, const qse_char_t* str, int* pvalue) qse_long_t v; const qse_char_t* end; - QSE_STRTONUM (v, str, &end, 0); + v = qse_strtolong (str, 0, &end); if (*end != '\0') { qse_raddic_seterrfmt (dic, QSE_RADDIC_ESYNERR, QSE_T("invalid number - %s"), str); @@ -1248,9 +1248,9 @@ static int sscanf_ui (qse_raddic_t* dic, const qse_char_t* str, qse_uintmax_t* p return -1; } - QSE_STRTONUM (v, str, &end, 0); - - if (*end != '\0') + /*QSE_STRTONUM (v, str, &end, 0);*/ + v = qse_strtouintmax (str, 0, &end); + if (*end != QSE_T('\0')) { qse_raddic_seterrfmt (dic, QSE_RADDIC_ESYNERR, QSE_T("invalid unsigned number - %s"), str); return -1; @@ -1260,6 +1260,7 @@ static int sscanf_ui (qse_raddic_t* dic, const qse_char_t* str, qse_uintmax_t* p return 0; } +#if 0 static int sscanf_ui32 (qse_raddic_t* dic, const qse_char_t* str, qse_uint32_t* pvalue, qse_uint32_t* pvalue2) { qse_long_t v, v2; @@ -1272,11 +1273,13 @@ static int sscanf_ui32 (qse_raddic_t* dic, const qse_char_t* str, qse_uint32_t* return -1; } - QSE_STRTONUM (v, str, &end, 0); + /*QSE_STRTONUM (v, str, &end, 0);*/ + v = qse_strtolong (str, 0, &end); if (pvalue2 && *end == '.') { start2 = end + 1; - QSE_STRTONUM (v2, start2, &end, 0); + /*QSE_STRTONUM (v2, start2, &end, 0);*/ + v2 = qse_strtolong (start2, 0, &end); } if (*end != '\0') @@ -1294,6 +1297,7 @@ static int sscanf_ui32 (qse_raddic_t* dic, const qse_char_t* str, qse_uint32_t* return 0; } +#endif /* * Process the ATTRIBUTE command @@ -1322,7 +1326,7 @@ static int process_attribute ( */ if (sscanf_ui(dic, argv[1], &value) <= -1 || value > QSE_TYPE_MAX(qse_uint16_t)) { - qse_raddic_seterrfmt (dic, QSE_RADDIC_ESYNERR, QSE_T("%s[%zd]: invalid attribute value %s"), fn, line, argv[1]); + qse_raddic_seterrfmt (dic, QSE_RADDIC_ESYNERR, QSE_T("%s[%zd]: invalid attribute value %s"), fn, line, argv[1]); return -1; } @@ -1530,9 +1534,10 @@ static int process_constant(qse_raddic_t* dic, const qse_char_t* fn, const qse_s */ static int process_vendor (qse_raddic_t* dic, const qse_char_t* fn, const qse_size_t line, qse_char_t** argv, int argc) { - int value; + unsigned int value; int continuation = 0; const qse_char_t* format = QSE_NULL; + const qse_char_t* end; if ((argc < 2) || (argc > 3)) { @@ -1541,14 +1546,18 @@ static int process_vendor (qse_raddic_t* dic, const qse_char_t* fn, const qse_si } /* - * Validate all entries + * Validate all entries */ - if (!QSE_ISDIGIT(argv[1][0])) + //if (!QSE_ISDIGIT(argv[1][0])) + //{ + // + //} + value = qse_strtoui(argv[1], 0, &end); + if (*end != QSE_T('\0') || value <= 0u || value > 65535u) { qse_raddic_seterrfmt (dic, QSE_RADDIC_ESYNERR, QSE_T("%s[%zd]: invalid value"), fn, line); return -1; } - value = qse_strtoi(argv[1], 0); /* Create a new VENDOR entry for the list */ if (qse_raddic_addvendor(dic, argv[0], value) == QSE_NULL) diff --git a/qse/lib/si/nwif-cfg.c b/qse/lib/si/nwif-cfg.c index 52cd2749..8d3b588c 100644 --- a/qse/lib/si/nwif-cfg.c +++ b/qse/lib/si/nwif-cfg.c @@ -342,7 +342,7 @@ static void read_proc_net_if_inet6 (qse_nwifcfg_t* cfg, struct ifreq* ifr) if (count >= 6) { - index = qse_mbsxtoi (tok[1].ptr, tok[1].len, 16); + index = qse_mbsxtoi (tok[1].ptr, tok[1].len, 16, QSE_NULL); if (index == cfg->index) { int ti; @@ -356,7 +356,7 @@ static void read_proc_net_if_inet6 (qse_nwifcfg_t* cfg, struct ifreq* ifr) cfg->addr.type = QSE_NWAD_IN6; - ti = qse_mbsxtoi (tok[2].ptr, tok[0].len, 16); + ti = qse_mbsxtoi (tok[2].ptr, tok[0].len, 16, QSE_NULL); qse_prefixtoip6ad (ti, &cfg->mask.u.in6.addr); cfg->mask.type = QSE_NWAD_IN6; diff --git a/qse/lib/si/sinfo.c b/qse/lib/si/sinfo.c index f9096a8c..0a0e6ce3 100644 --- a/qse/lib/si/sinfo.c +++ b/qse/lib/si/sinfo.c @@ -65,7 +65,8 @@ int qse_get_highest_fd (void) if (de->d_name[0] == QSE_MT('.')) continue; - QSE_MBSTONUM (l, de->d_name, &endptr, 10); + /*QSE_MBSTONUM (l, de->d_name, &endptr, 10);*/ + l = qse_mbstolong (de->d_name, 10, &endptr); if (*endptr == QSE_MT('\0')) { fd = (int)l; @@ -137,7 +138,8 @@ int qse_close_open_fds_using_proc (int* excepts, qse_size_t count) if (de->d_name[0] == QSE_MT('.')) continue; - QSE_MBSTONUM (l, de->d_name, &endptr, 10); + /*QSE_MBSTONUM (l, de->d_name, &endptr, 10);*/ + l = qse_mbstolong (de->d_name, 10, &endptr); if (*endptr == QSE_MT('\0')) { int fd = (int)l;