From ff08a6b40216dee03e314f1de4785ffe865e1fdb Mon Sep 17 00:00:00 2001 From: Thong Thai Date: Tue, 25 Apr 2023 16:05:34 -0400 Subject: [PATCH] tgsi: use locale independent float and double parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The atof and strtod functions use the locale of the user when determining if a decimal is a comma, ',' or a period, '.'. Thanks to @fzwoch for helping find the cause of a shader-related issue. Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5760 Signed-off-by: Thong Thai Acked-by: Marek Olšák Part-of: (cherry picked from commit 9c4e3c90206a4ba6b77a3370344510371cd3a1f6) --- .pick_status.json | 2 +- src/gallium/auxiliary/tgsi/tgsi_text.c | 50 +++----------------------- 2 files changed, 5 insertions(+), 47 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index fad6949fd73..683a6992166 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -940,7 +940,7 @@ "description": "tgsi: use locale independent float and double parsing", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index 7802f10498d..29e3372781b 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -30,6 +30,7 @@ #include "util/u_prim.h" #include "pipe/p_defines.h" #include "util/u_inlines.h" +#include "util/strtod.h" #include "tgsi_text.h" #include "tgsi_build.h" #include "tgsi_info.h" @@ -231,52 +232,9 @@ static boolean parse_identifier( const char **pcur, char *ret, size_t len ) static boolean parse_float( const char **pcur, float *val ) { const char *cur = *pcur; - boolean integral_part = FALSE; - boolean fractional_part = FALSE; - - if (*cur == '0' && *(cur + 1) == 'x') { - union fi fi; - fi.ui = strtoul(cur, NULL, 16); - *val = fi.f; - cur += 10; - goto out; - } - - *val = (float) atof( cur ); - if (*cur == '-' || *cur == '+') - cur++; - if (is_digit( cur )) { - cur++; - integral_part = TRUE; - while (is_digit( cur )) - cur++; - } - if (*cur == '.') { - cur++; - if (is_digit( cur )) { - cur++; - fractional_part = TRUE; - while (is_digit( cur )) - cur++; - } - } - if (!integral_part && !fractional_part) + *val = _mesa_strtof(cur, (char**)pcur); + if (*pcur == cur) return FALSE; - if (uprcase( *cur ) == 'E') { - cur++; - if (*cur == '-' || *cur == '+') - cur++; - if (is_digit( cur )) { - cur++; - while (is_digit( cur )) - cur++; - } - else - return FALSE; - } - -out: - *pcur = cur; return TRUE; } @@ -288,7 +246,7 @@ static boolean parse_double( const char **pcur, uint32_t *val0, uint32_t *val1) uint32_t uval[2]; } v; - v.dval = strtod(cur, (char**)pcur); + v.dval = _mesa_strtod(cur, (char**)pcur); if (*pcur == cur) return FALSE;