From 2840164aca498473fd396a557f95178f81c301ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 10 Nov 2025 11:13:54 +0100 Subject: [PATCH] Fix NUL characters in FORMAT() output Fixes https://bugs.mysql.com/bug.php?id=82085 In `sql/sql/locale.cc` there is this for `bg_BG`: ``` '\0', /* thousands_sep bg_BG */ "\x03\x03", /* grouping bg_BG */ ``` Other locales that set `\0` as thousounds separator have grouping set to `\x80\x80`, but the `bg_BG` locale doesn't. The result is that `FORMAT(12345.67,3,'bg_BG')` has a NUL character as thousands separator. Before this commit: ``` mysql> SELECT FORMAT(12345.67, 3, 'bg_BG'); +------------------------------+ | FORMAT(12345.67, 3, 'bg_BG') | +------------------------------+ | 12 345,670 | +------------------------------+ 1 row in set (0.001 sec) mysql> SELECT HEX(FORMAT(12345.67, 3, 'bg_BG')); +-----------------------------------+ | HEX(FORMAT(12345.67, 3, 'bg_BG')) | +-----------------------------------+ | 3132003334352C363730 | +-----------------------------------+ 1 row in set (0.001 sec) ``` With this commit: ``` mysql> SELECT FORMAT(12345.67,3,'bg_BG'); +----------------------------+ | FORMAT(12345.67,3,'bg_BG') | +----------------------------+ | 12345,670 | +----------------------------+ 1 row in set (0.001 sec) mysql> SELECT HEX(FORMAT(12345.67,3,'bg_BG')); +---------------------------------+ | HEX(FORMAT(12345.67,3,'bg_BG')) | +---------------------------------+ | 31323334352C363730 | +---------------------------------+ 1 row in set (0.001 sec) ``` --- sql/item_strfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 064c533fb21a..386f72589cc3 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2441,7 +2441,7 @@ String *Item_func_format::val_str_ascii(String *str) { count will be initialized to -1 and we'll never get into this "if" anymore. */ - if (count == 0) { + if ((count == 0) && (lc->thousand_sep != '\0')) { *--dst = lc->thousand_sep; if (grouping[1]) grouping++; count = *grouping;