Skip to content

sv_parser: return lexer character tokens as unsigned char - #9

Open
Xeonacid wants to merge 1 commit into
sodabrew:libsieve-2.3from
Xeonacid:fix/unsigned-char-lexers
Open

sv_parser: return lexer character tokens as unsigned char#9
Xeonacid wants to merge 1 commit into
sodabrew:libsieve-2.3from
Xeonacid:fix/unsigned-char-lexers

Conversation

@Xeonacid

@Xeonacid Xeonacid commented Aug 1, 2026

Copy link
Copy Markdown

The sieve catch-all rule and the addr special-character rules used "return yytext[0]". That expression is not portable: its value depends on whether plain char is signed.

Bison treats any yylex() result <= 0 as end-of-input. After a successful scan, flex can present a 0xff byte to the catch-all rule. On signed-char hosts (e.g. x86) that becomes -1 and is accepted as EOF; on unsigned-char hosts (RISC-V Linux, many ARM ABIs) it becomes token 255, the parse fails with a syntax error, and every non-trivial script is rejected.

Cast the octet through unsigned char so the token is always in 0..255, and map 0xff to EOF so both kinds of ABI finish the token stream the same way. Apply the same cast to addr-lex special-character returns.

Fixes #6

The sieve catch-all rule and the addr special-character rules used
"return yytext[0]".  That expression is not portable: its value depends
on whether plain char is signed.

Bison treats any yylex() result <= 0 as end-of-input.  After a successful
scan, flex can present a 0xff byte to the catch-all rule.  On signed-char
hosts (e.g. x86) that becomes -1 and is accepted as EOF; on unsigned-char
hosts (RISC-V Linux, many ARM ABIs) it becomes token 255, the parse
fails with a syntax error, and every non-trivial script is rejected.

Cast the octet through unsigned char so the token is always in 0..255,
and map 0xff to EOF so both kinds of ABI finish the token stream the
same way.  Apply the same cast to addr-lex special-character returns.
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.

yy_parse completely fails on riscv64 architecture

1 participant