https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128222
Bug ID: 128222
Summary: libquadmath: quadmath_snprintf returns 0 for
"%.2147483647Qa"
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libquadmath
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
#include <quadmath.h>
int main(void)
{
char buf[64];
int r = quadmath_snprintf(buf, sizeof buf, "%.2147483647Qa", (__float128)
1.5);
if (r == 0)
__builtin_abort();
return 0;
}
Program returned: 134
Program stderr
Program terminated with signal SIGABRT (6)
With precision 2147483647, %Qa of 1.5 is "0x1.8" followed by 2147483646 zeros
and "p+0", which is 2147483654 characters. That is more than INT_MAX, so
quadmath_snprintf cannot return the length and has to report an error. The
output is not empty, so 0 is never a valid result. Instead quadmath_snprintf
returns 0 and main aborts. With precision 2147483640 the output is exactly
INT_MAX characters and quadmath_snprintf correctly returns 2147483647.
Compiler Explorer:
https://godbolt.org/z/eE79nzWj7