Skip to content

[wasm2c] Use locale-independent ctype in GenerateHeaderGuard - #2759

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:header-guard-ctype
Jun 15, 2026
Merged

sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:header-guard-ctype

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Spotted while reading CWriter for locale-sensitive calls.

src/c-writer.cc:1531:  isalnum(c)    // c is plain `char`
src/c-writer.cc:1532:  toupper(c)

header_name_ is the output header filename. char is signed on most targets, so any byte >= 0x80 (a non-ASCII output path) reaches these calls as a negative value. Passing anything other than EOF or an unsigned char value to them is undefined behaviour. toupper is locale-sensitive on top of that.

The file already defines internal_isalpha/isdigit/isalnum/ishexdigit on uint8_t for this exact reason (the comment above them spells it out), used throughout Mangle. GenerateHeaderGuard was the lone holdout. Routed it through internal_isalnum plus a matching internal_toupper. Guards for ASCII header names come out byte-identical.

@sbc100 sbc100 changed the title use locale-independent ctype in GenerateHeaderGuard [wasm2c] Use locale-independent ctype in GenerateHeaderGuard Jun 15, 2026
@sbc100
sbc100 merged commit e6053b8 into WebAssembly:main Jun 15, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants