Fix printing decimal-point character on printf %#a (#1296)

The C standard indicates that when processing the a conversion specifier
"if the precision is zero *and* the # flag is not specified, no decimal-
point character appears.". This means that __fmt needs to ensure that it
prints the decimal-point character not only when the precision is non-0,
but also when the # flag is specified - cosmopolitan currently does not.

This patch fixes this, along with adding a few tests for this behaviour.
This commit is contained in:
Gabriel Ravier 2024-09-16 01:42:51 +02:00 committed by GitHub
parent ef62730ae4
commit 81bc8d0963
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 5 deletions

View file

@ -1497,9 +1497,13 @@ int __fmt(void *fn, void *arg, const char *format, va_list va, int *wrote) {
i1 = prec1 & 7;
k = prec1 >> 3;
__FMT_PUT(alphabet[(fpb.bits[k] >> 4 * i1) & 0xf]);
if (prec1 > 0 || prec > 0) {
// decimal-point character appears if the precision isn't 0
// or the # flag is specified
if (prec1 > 0 || prec > 0 || (flags & FLAGS_HASH)) {
__FMT_PUT('.');
}
while (prec1 > 0) {
if (--i1 < 0) {
if (--k < 0)