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:
Gabriel Ravier 2024-09-07 04:34:24 +02:00 committed by GitHub
parent d1157d471f
commit c66abd7260
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 108 additions and 6 deletions

View file

@ -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':