mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 22:38:30 +00:00
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:
parent
ef62730ae4
commit
81bc8d0963
2 changed files with 26 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue