Skip to content

Commit

Permalink
Fix RP6502 varargs usage
Browse files Browse the repository at this point in the history
All char varargs arguments are promoted to unsigned, so they must be
extracted as unsigned and casted back to char. The compiler should
optimize this away, but it's required to avoid undefined behavior.

It's also undefined behavior to pass the char count to va_start, but
fixing that wouldn't be transparent, and I think it should probably be
safe; we don't really use the argument to va_start.
  • Loading branch information
mysterymath committed Jan 29, 2024
1 parent 621228d commit 90f616f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mos-platform/rp6502/xregn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int xregn(char device, char channel, unsigned char address, unsigned char count,
RIA.xstack = channel;
RIA.xstack = address;
for (unsigned char i = 0; i < count; i++)
RIA.xstack = va_arg(args, unsigned char);
RIA.xstack = (char)va_arg(args, unsigned);
va_end(args);
RIA.op = RIA_OP_XREG;
while (RIA.busy & RIA_BUSY_BIT)
Expand Down

0 comments on commit 90f616f

Please sign in to comment.