Tk Source Code

View Ticket
Login
Ticket UUID: 9e89324a0a79321a32dc48dd914821a2da31c05
Title: spinbox parses its value with sscanf("%lf"), which depends on the LC_NUMERIC locale
Type: Bug Version: 8.6, 9.0, 9.1b1
Submitter: serhiy.storchaka Created on: 2026-09-20 17:52:13
Subsystem: 17. [spinbox] Assigned To: jan.nijtmans
Priority: 1 Zero Severity: Important
Status: Closed Last Modified: 2026-09-25 06:29:48
Resolution: Fixed Closed By: oehhar
    Closed on: 2026-09-25 06:29:48
Description:

The spinbox parses the current value with sscanf("%lf") when the up/down button is invoked and when -from/-to are configured. sscanf() honours LC_NUMERIC, so after an extension or the embedding application has called setlocale(LC_NUMERIC, "") on a system with a decimal comma (de_DE, fr_FR, uk_UA, ...), "0.5" is read as 0:

spinbox .sb -from 0 -to 1 -increment 0.1 -format %.1f
.sb insert 0 0.5
.sb invoke buttonup   ;# 0.1 instead of 0.6
set v 0.7
spinbox .sb2 -from 0 -to 1 -increment 0.1 -format %.1f -textvariable v
.sb2 configure -from 0.2   ;# v becomes 0.2 instead of staying 0.7

Tested on main (9.1b1) and 8.6.17 with setlocale(LC_NUMERIC, "de_DE.utf8") called after Tk_Init. This is the parsing counterpart of [348b482ff7]; the general ticket is [2112563]. The value reported to AT-SPI by tkUnixAccessibility.c is parsed with atof() and has the same problem.

User Comments: oehhar added on 2026-09-25 06:29:48:

Jan has merged the fix by [8ebff84d]. I suppose, we can close this one.

Thanks, Harald


serhiy.storchaka added on 2026-09-24 08:19:32:

Reopened: on core-8-6-branch [e0dd3fdb59] brings back the octal problem of [2358545fff], which 8.5.10 fixed by using sscanf(). In Tcl 8.6, Tcl_GetDouble() treats "08" as invalid octal and "010" as 8, so a spinbox with -format %02.0f goes 07 → 08 → 00. Fix for 8.6 on spinbox-octal-86: strip leading zeros before Tcl_GetDouble(), test spinbox-26.2. 9.0 and trunk are not affected, since Tcl 9 does not parse leading zeros as octal; spinbox-octal-test adds the same test for trunk.


jan.nijtmans added on 2026-09-22 15:11:34:

Fixed on [009719f2f9e1422e|trunk], and also in core-9-0-branch and core-8-6-branch.

Many thanks, @serhiy.storchaka


serhiy.storchaka added on 2026-09-20 17:53:42:

Fixed on branch spinbox-locale-parse in [a13d8dbafb]: the value is parsed with Tcl_GetDouble(), like the -from, -to and -increment options.