Re: [Mesa-dev] [PATCH] gallium/util: make use of strtol() in debug_get_num_option()
On 09/19/2016 11:59 PM, Brian Paul wrote: Seems OK here. Tested-by: Brian PaulThanks for testing and reviewing guys. On 09/19/2016 02:43 AM, Nicolai Hähnle wrote: Reviewed-by: Nicolai Hähnle However, you might want to check with the VMWare guys. I seem to recall that MSVC is a bit peculiar with some of these library functions. Cheers, Nicolai On 14.09.2016 20:37, Samuel Pitoiset wrote: This allows to use hexadecimal numbers which are automatically detected by strtol() when the base is 0. Signed-off-by: Samuel Pitoiset --- src/gallium/auxiliary/util/u_debug.c | 25 - 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 4619526..dd3e167 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -203,25 +203,16 @@ debug_get_num_option(const char *name, long dfault) const char *str; str = os_get_option(name); - if (!str) + if (!str) { result = dfault; - else { - long sign; - char c; - c = *str++; - if (c == '-') { - sign = -1; - c = *str++; - } - else { - sign = 1; - } - result = 0; - while ('0' <= c && c <= '9') { - result = result*10 + (c - '0'); - c = *str++; + } else { + char *endptr; + + result = strtol(str, , 0); + if (str == endptr) { + /* Restore the default value when no digits were found. */ + result = dfault; } - result *= sign; } if (debug_get_option_should_print()) ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] gallium/util: make use of strtol() in debug_get_num_option()
Seems OK here. Tested-by: Brian PaulOn 09/19/2016 02:43 AM, Nicolai Hähnle wrote: Reviewed-by: Nicolai Hähnle However, you might want to check with the VMWare guys. I seem to recall that MSVC is a bit peculiar with some of these library functions. Cheers, Nicolai On 14.09.2016 20:37, Samuel Pitoiset wrote: This allows to use hexadecimal numbers which are automatically detected by strtol() when the base is 0. Signed-off-by: Samuel Pitoiset --- src/gallium/auxiliary/util/u_debug.c | 25 - 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 4619526..dd3e167 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -203,25 +203,16 @@ debug_get_num_option(const char *name, long dfault) const char *str; str = os_get_option(name); - if (!str) + if (!str) { result = dfault; - else { - long sign; - char c; - c = *str++; - if (c == '-') { - sign = -1; - c = *str++; - } - else { - sign = 1; - } - result = 0; - while ('0' <= c && c <= '9') { - result = result*10 + (c - '0'); - c = *str++; + } else { + char *endptr; + + result = strtol(str, , 0); + if (str == endptr) { + /* Restore the default value when no digits were found. */ + result = dfault; } - result *= sign; } if (debug_get_option_should_print()) ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] gallium/util: make use of strtol() in debug_get_num_option()
Reviewed-by: Nicolai HähnleHowever, you might want to check with the VMWare guys. I seem to recall that MSVC is a bit peculiar with some of these library functions. Cheers, Nicolai On 14.09.2016 20:37, Samuel Pitoiset wrote: This allows to use hexadecimal numbers which are automatically detected by strtol() when the base is 0. Signed-off-by: Samuel Pitoiset --- src/gallium/auxiliary/util/u_debug.c | 25 - 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 4619526..dd3e167 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -203,25 +203,16 @@ debug_get_num_option(const char *name, long dfault) const char *str; str = os_get_option(name); - if (!str) + if (!str) { result = dfault; - else { - long sign; - char c; - c = *str++; - if (c == '-') { -sign = -1; -c = *str++; - } - else { -sign = 1; - } - result = 0; - while ('0' <= c && c <= '9') { -result = result*10 + (c - '0'); -c = *str++; + } else { + char *endptr; + + result = strtol(str, , 0); + if (str == endptr) { + /* Restore the default value when no digits were found. */ + result = dfault; } - result *= sign; } if (debug_get_option_should_print()) ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] gallium/util: make use of strtol() in debug_get_num_option()
This allows to use hexadecimal numbers which are automatically detected by strtol() when the base is 0. Signed-off-by: Samuel Pitoiset--- src/gallium/auxiliary/util/u_debug.c | 25 - 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 4619526..dd3e167 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -203,25 +203,16 @@ debug_get_num_option(const char *name, long dfault) const char *str; str = os_get_option(name); - if (!str) + if (!str) { result = dfault; - else { - long sign; - char c; - c = *str++; - if (c == '-') { -sign = -1; -c = *str++; - } - else { -sign = 1; - } - result = 0; - while ('0' <= c && c <= '9') { -result = result*10 + (c - '0'); -c = *str++; + } else { + char *endptr; + + result = strtol(str, , 0); + if (str == endptr) { + /* Restore the default value when no digits were found. */ + result = dfault; } - result *= sign; } if (debug_get_option_should_print()) -- 2.8.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev