cosmopolitan/libc/fmt
Gabriel Ravier 12e07798df
Fix printf precision/field width being limited by internal buffer size (#799)
The C standard, when defining field width and precision, never gives
any limit on the values used for them (except, I believe, that they
fit within an int). In other words, if the user gives a field width of
32145 and a precision of 9218, the implementation has to handle these
values correctly. However, when such kinds of high numbers are used
with integer conversions, cosmopolitan is limited by an internal
buffer size of 144, which means precisions and field widths have to
fit within this, which violates the standard.

This means that for example, the following program:

 #include <stdio.h>
 #include <string.h>

int main()
{
    char buf2[512] = {};

    int i = snprintf(buf2, sizeof(buf2), "%.9999u", 10);
    printf("%d %zu\n", i, strlen(buf2));
}

would, instead of printing "9999 511" (the correct output), instead
print "144 144" under cosmopolitan.

This patch fixes this.
2023-04-04 14:16:34 -04:00
..
__xpg_strerror_r.c Unbloat the build 2022-08-11 00:15:29 -07:00
abs.c Make improvements 2022-04-24 10:06:05 -07:00
atoi.c Improve cosmo's conformance to libc-test 2022-10-10 17:52:41 -07:00
atol.c Add cpu / mem / fsz limits to build system 2021-08-13 23:40:53 -07:00
atoll.c Add cpu / mem / fsz limits to build system 2021-08-13 23:40:53 -07:00
basename.c Make improvements 2022-07-21 03:36:42 -07:00
bing.c Make unbing() not need initialization 2022-10-07 14:56:02 -07:00
bing.internal.h Enhance chibicc 2020-12-09 04:00:48 -08:00
conv.h Introduce clock_nanosleep() 2022-10-05 06:37:15 -07:00
decodenf32.c Update experiment with tty audio 2022-07-15 23:07:32 -07:00
dirname.c Fix basename() and dirname() 2022-04-06 00:13:44 -07:00
div.c Change license 2020-12-27 17:18:44 -08:00
divmod10.internal.h Make improvements 2022-03-16 13:40:10 -07:00
encodenf32.c Update experiment with tty audio 2022-07-15 23:07:32 -07:00
fmt.c Fix issues 774, 782 and 789 (printf precision bugs) (#790) 2023-03-29 01:11:48 -07:00
fmt.h Rename hidden keyword to _Hide 2022-11-08 12:55:28 -08:00
fmt.internal.h Rename hidden keyword to _Hide 2022-11-08 12:55:28 -08:00
fmt.mk Use private keyword on makefile target variables 2022-08-10 18:36:11 -07:00
formatbinary64.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
formatflex64.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
formathex64.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
formatint64thousands.c Add torture test for zipos file descriptors 2022-06-15 16:29:49 -07:00
formatoctal32.c Do code cleanup use duff device linenoise i/o 2022-04-22 18:56:52 -07:00
formatoctal64.c Polish redbean serialization 2022-04-29 06:10:10 -07:00
i128abs.c Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
imaxabs.c Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
imaxdiv.c Add imaxdiv, wcscoll, getdtablesize (#639) 2022-10-05 07:14:58 -07:00
internal.h Support proper %g, %f, and %a float formatting 2021-03-05 10:31:16 -08:00
itoa.c Support proper %g, %f, and %a float formatting 2021-03-05 10:31:16 -08:00
itoa.h Polyfill statfs() and fstatfs() on BSD distros 2022-08-17 14:54:03 -07:00
itoa64.c Fold LIBC_ALG into LIBC_MEM 2022-08-13 08:32:34 -07:00
itoa64fixed16.greg.c Fix bugs and make code tinier 2022-10-09 23:21:34 -07:00
itoa64radix8.c Fold LIBC_ALG into LIBC_MEM 2022-08-13 08:32:34 -07:00
itoa64radix16.greg.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
itoa128radix10.greg.c Fold LIBC_ALG into LIBC_MEM 2022-08-13 08:32:34 -07:00
joinpaths.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
knfcimal.S Update experiment with tty audio 2022-07-15 23:07:32 -07:00
labs.c Make improvements 2022-04-24 10:06:05 -07:00
ldiv.c Change license 2020-12-27 17:18:44 -08:00
leb128.h Support Linux binfmt_misc and APE loading on Apple 2022-05-21 09:28:25 -07:00
llabs.c Make improvements 2022-04-24 10:06:05 -07:00
lldiv.c Change license 2020-12-27 17:18:44 -08:00
magnumstrs.internal.h Rename hidden keyword to _Hide 2022-11-08 12:55:28 -08:00
nf32.h Update experiment with tty audio 2022-07-15 23:07:32 -07:00
ntoa.c Fix printf precision/field width being limited by internal buffer size (#799) 2023-04-04 14:16:34 -04:00
pad.c Make more fixes and improvements 2022-04-21 13:44:59 -07:00
pflink.h Fix PFLINK mechanism for uppercase float conversion specifiers (#796) 2023-03-29 22:18:59 -04:00
sizetol.c Make improvements 2022-08-15 15:20:36 -07:00
sleb64.c Productionize new APE loader and more 2021-10-02 08:27:03 -07:00
sleb128.c Productionize new APE loader and more 2021-10-02 08:27:03 -07:00
snprintf.c Support proper %g, %f, and %a float formatting 2021-03-05 10:31:16 -08:00
sprintf.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
sscanf.c Change license 2020-12-27 17:18:44 -08:00
stoa.c Make important improvements 2022-09-14 22:39:08 -07:00
strerror.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
strerror_r.c Make improvements 2022-08-15 15:20:36 -07:00
stripext.c Make numerous improvements 2021-09-28 01:52:34 -07:00
stripexts.c Add SNI support to redbean and improve SSL perf 2021-07-23 13:56:13 -07:00
strtoi128.c Make important improvements 2022-09-14 22:39:08 -07:00
strtoimax.c Make important improvements 2022-09-14 22:39:08 -07:00
strtol.c Greatly expand system() shell code features 2022-10-11 21:30:31 -07:00
strtol.internal.h Greatly expand system() shell code features 2022-10-11 21:30:31 -07:00
strtoll.c Fix typo bug in strtoll (#245) 2021-08-15 12:07:33 -07:00
strtoll_l.c Fold LIBC_UNICODE into LIBC_STR 2022-08-13 08:42:32 -07:00
strtonum.c Change license 2020-12-27 17:18:44 -08:00
strtou128.c Make important improvements 2022-09-14 22:39:08 -07:00
strtoul.c Improve cosmo's conformance to libc-test 2022-10-10 17:52:41 -07:00
strtoull.c Add cpu / mem / fsz limits to build system 2021-08-13 23:40:53 -07:00
strtoull_l.c Fold LIBC_UNICODE into LIBC_STR 2022-08-13 08:42:32 -07:00
strtoumax.c Make important improvements 2022-09-14 22:39:08 -07:00
swprintf.c Fix bugs and make code tinier 2022-10-09 23:21:34 -07:00
uleb64.c Add Compress() and Uncompress() to redbean 2022-05-16 16:49:20 -07:00
uleb128.c Productionize new APE loader and more 2021-10-02 08:27:03 -07:00
unbing.c Make unbing() not need initialization 2022-10-07 14:56:02 -07:00
unhexbuf.c Fix bugs and make code tinier 2022-10-09 23:21:34 -07:00
unsleb128.c Change license 2020-12-27 17:18:44 -08:00
unuleb64.c Add Compress() and Uncompress() to redbean 2022-05-16 16:49:20 -07:00
unzleb64.c Productionize new APE loader and more 2021-10-02 08:27:03 -07:00
vcscanf.c Make important improvements 2022-09-14 22:39:08 -07:00
vsnprintf.c Fix memcpy(size=0) ubsan warning in vsnprintf() 2023-03-29 01:28:10 -07:00
vsprintf.c Support proper %g, %f, and %a float formatting 2021-03-05 10:31:16 -08:00
vsscanf.c Change license 2020-12-27 17:18:44 -08:00
wcscoll.c Add imaxdiv, wcscoll, getdtablesize (#639) 2022-10-05 07:14:58 -07:00
wcstoi128.c Make important improvements 2022-09-14 22:39:08 -07:00
wcstoimax.c Make important improvements 2022-09-14 22:39:08 -07:00
wcstol.c Make important improvements 2022-09-14 22:39:08 -07:00
wcstoll.c Make important improvements 2022-09-14 22:39:08 -07:00
wcstoll_l.c Fold LIBC_UNICODE into LIBC_STR 2022-08-13 08:42:32 -07:00
wcstou128.c Make important improvements 2022-09-14 22:39:08 -07:00
wcstoul.c Greatly expand system() shell code features 2022-10-11 21:30:31 -07:00
wcstoull.c Make important improvements 2022-09-14 22:39:08 -07:00
wcstoull_l.c Fold LIBC_UNICODE into LIBC_STR 2022-08-13 08:42:32 -07:00
wcstoumax.c Make important improvements 2022-09-14 22:39:08 -07:00
zleb64.c Support Linux binfmt_misc and APE loading on Apple 2022-05-21 09:28:25 -07:00
zleb128.c Productionize new APE loader and more 2021-10-02 08:27:03 -07:00