pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with psprintf and intmax_t (%jd)
2+ messages / 2 participants
[nested] [flat]
* Problem with psprintf and intmax_t (%jd)
@ 2020-11-13 16:22 Jan Behrens <jbe-mlist@magnetkern.de>
2020-11-13 16:52 ` Re: Problem with psprintf and intmax_t (%jd) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Jan Behrens @ 2020-11-13 16:22 UTC (permalink / raw)
To: pgsql-general
Dear all,
I'm facing a problem with psprintf and the %jd format string. I used
the following C-code:
PG_RETURN_CSTRING(psprintf("%d@%jd", (int)1, (intmax_t)2));
While this worked fine in past, I recently get (with PostgreSQL 13):
ERROR: vsnprintf failed: Invalid argument with format string "%d@%jd"
I was not able to figure out what's the problem. Apparently this error
is thrown when vsnprintf(buf, len, fmt, args) in src/common/psprintf.c
returns a negative value. However, calling snprintf(buf, len, "%d@%jd",
(int)1, (intmax_t)2)) in a separate test program works fine on my
system.
I found a workaround. The following call works fine:
PG_RETURN_CSTRING(psprintf("%d@%lld", (int)1, (long long)2));
I could live with the workaround, but it is a bit scary, as I don't
really understand why "%jd" fails while "%lld" does not. Does anyone
know why, and/or is it possible for anyone else to reproduce the
problem?
Kind regards,
Jan Behrens
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Problem with psprintf and intmax_t (%jd)
2020-11-13 16:22 Problem with psprintf and intmax_t (%jd) Jan Behrens <jbe-mlist@magnetkern.de>
@ 2020-11-13 16:52 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2020-11-13 16:52 UTC (permalink / raw)
To: Jan Behrens <jbe-mlist@magnetkern.de>; +Cc: pgsql-general
Jan Behrens <jbe-mlist@magnetkern.de> writes:
> I'm facing a problem with psprintf and the %jd format string. I used
> the following C-code:
> PG_RETURN_CSTRING(psprintf("%d@%jd", (int)1, (intmax_t)2));
> While this worked fine in past, I recently get (with PostgreSQL 13):
> ERROR: vsnprintf failed: Invalid argument with format string "%d@%jd"
Before PG 12, this would have worked (on many platforms) if your
local libc's printf understood the "j" modifier. Since v12, we use
src/port/snprintf.c on every platform, and it doesn't know "j".
By and large, we do not use the <stdint.h> types in Postgres, and are
unlikely to start doing so. So this omission doesn't particularly
concern me. "ll" with a cast to "long long" is indeed the recommended
practice if you want to print a 64-bit value.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-11-13 16:52 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 16:22 Problem with psprintf and intmax_t (%jd) Jan Behrens <jbe-mlist@magnetkern.de>
2020-11-13 16:52 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox