Skip to content

[bug] printf %d with a multibyte char constant uses the code point in the C locale; GNU uses the first byte #2965

Closed

Description

@caomengxuan666

[bug] printf %d with a multibyte char constant uses the code point in the C locale; GNU uses the first byte

Repro

LC_ALL=C bash -c "printf '%d\n' \"'é\""
# GNU bash 5.3.20: 195
LC_ALL=C rubash -c "printf '%d\n' \"'é\""
# rubash: 233

Expected (GNU)

In a single-byte locale, the '<char> character constant of printf %d
takes the first byte of the character: é is UTF-8 0xC3 0xA9, so GNU
prints 195.

Actual (rubash)

rubash prints 233, the Unicode code point U+00E9, regardless of locale.

Scope

The divergence is C-locale-only: under LC_ALL=C.UTF-8 both shells print
233 for 'é and 8364 for '€. Morphology (all in LC_ALL=C, two
passes, stable):

input GNU rubash
'é 195 233
'ü 195 252
'€ 226 8364
'😀 240 128512
'ß 195 223
'ñ 195 241
'Ā 196 256
'é '€ (two args) 195 226 233 8364

Same in both shells (controls): ASCII 'a → 97; C.UTF-8 'é/'€ →
233/8364; invalid bytes $'\xff' / $'\x80' → identical invalid number
diagnostic, rc 1; printf '%d' "'" → 0; $(( 'é' )) is an arithmetic
syntax error in both shells (no char-constant support on that surface).

Environment

  • rubash master 5133187592fd6f97ed55f0260762475f3986e337 (fresh build,
    verified on that binary)
  • oracle: self-built GNU bash 5.3.20
  • locale: LC_ALL=C (divergence); LC_ALL=C.UTF-8 (agreement)

Regression seed:

LC_ALL=C; export LC_ALL
[ "$(printf '%d\n' "'é")" = "195" ] && echo "printf-charconst-e: PASS" || echo "printf-charconst-e: FAIL"
[ "$(printf '%d\n' "'€")" = "226" ] && echo "printf-charconst-euro: PASS" || echo "printf-charconst-euro: FAIL"
[ "$(printf '%d\n' "'😀")" = "240" ] && echo "printf-charconst-emoji: PASS" || echo "printf-charconst-emoji: FAIL"
[ "$(printf '%d\n' "'a")" = "97" ] && echo "printf-charconst-ascii: PASS" || echo "printf-charconst-ascii: FAIL"

Seed verified: GNU 4/4 PASS; rubash 3 FAIL + ASCII PASS (both via
LC_ALL=C in the environment and via in-script export LC_ALL=C).

Activity

  1. added
    bug
    gnu-baseline
    area:builtins
    on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:builtinsbuggnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions