This is an automated email from the ASF dual-hosted git repository. ChristopherSchultz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat-connectors.git
commit 83c4ef518028d8d43f413422cc8f2c1314b0de5a Author: Christopher Schultz <[email protected]> AuthorDate: Mon Jun 8 16:13:55 2026 -0400 Improve performance Don't bother converting from int -> string -> int Use strtol instead of atof to get error handling --- native/common/jk_map.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/native/common/jk_map.c b/native/common/jk_map.c index 04eb325a4..116efd868 100644 --- a/native/common/jk_map.c +++ b/native/common/jk_map.c @@ -201,31 +201,35 @@ const char *jk_map_get_string(jk_map_t *m, const char *name, const char *def) int jk_map_get_int(jk_map_t *m, const char *name, int def) { - char buf[100]; - const char *rc; - size_t len; - int int_res; + const char *rc = jk_map_get_string(m, name, NULL); + char *end; + long l; + long multit = 1; - sprintf(buf, "%d", def); - rc = jk_map_get_string(m, name, buf); + if (rc == NULL) { + return def; + } - len = strlen(rc); - if (len) { - const char *lastchar = &rc[0] + len - 1; - int multit = 1; - if ('m' == *lastchar || 'M' == *lastchar) { - multit = 1024 * 1024; - } - else if ('k' == *lastchar || 'K' == *lastchar) { - multit = 1024; - } - /* Safe because atoi() will stop at any non-numeric lastchar */ - int_res = atoi(rc) * multit; + errno = 0; + + l = strtol(rc, &end, 10); + + if (end == rc || errno == ERANGE) { + return def; } - else - int_res = def; - return int_res; + char c = *end; + if (c == 'm' || c == 'M') { + multit = 1024 * 1024; + } else if (c == 'k' || c == 'K') { + multit = 1024; + } + + if (l > INT_MAX / multit || l < INT_MIN / multit) { + return def; + } + + return (int)(l * multit); } double jk_map_get_double(jk_map_t *m, const char *name, double def) @@ -239,6 +243,7 @@ double jk_map_get_double(jk_map_t *m, const char *name, double def) } errno = 0; + d = strtod(rc, &end); if (end == rc || errno == ERANGE) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
