mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 19:22:27 +00:00
Implement length modifiers for printf %n conv spec (#1278)
The C Standard specifies that, when a conversion specification specifies a conversion specifier of n, the type of the passed pointer is specified by the length modifier (if any), i.e. that e.g. the argument for %hhn is of type signed char *, but Cosmopolitan currently does not handle this - instead always simply assuming that the pointer always points to an int. This patch implements, and tests, length modifiers with the n conversion specifier, with the tests testing all of the available length modifiers.
This commit is contained in:
parent
d1157d471f
commit
c66abd7260
2 changed files with 108 additions and 6 deletions
|
@ -1125,7 +1125,25 @@ int __fmt(void *fn, void *arg, const char *format, va_list va, int *wrote) {
|
|||
}
|
||||
break;
|
||||
case 'n':
|
||||
*va_arg(va, int *) = *wrote;
|
||||
switch (signbit) {
|
||||
case 7:
|
||||
*va_arg(va, int8_t *) = *wrote;
|
||||
break;
|
||||
case 15:
|
||||
*va_arg(va, int16_t *) = *wrote;
|
||||
break;
|
||||
case 31:
|
||||
*va_arg(va, int32_t *) = *wrote;
|
||||
break;
|
||||
case 63:
|
||||
*va_arg(va, int64_t *) = *wrote;
|
||||
break;
|
||||
case 127:
|
||||
*va_arg(va, int128_t *) = *wrote;
|
||||
break;
|
||||
default:
|
||||
npassert(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue