Re: BUG #19771: to_char(): NUL byte in result for formats with a trailing decimal point (regression from ec352b37d)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gowtham Reddy <gowthamdoma18(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19771: to_char(): NUL byte in result for formats with a trailing decimal point (regression from ec352b37d)
Date: 2026-10-19 00:41:05
Message-ID: 347653.1792370465@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Gowtham Reddy <gowthamdoma18(at)gmail(dot)com> writes:
> Please find attached a proposed patch for BUG #NNNNN.
> It stops NUM_numpart_to_char() from emitting the number string's
> terminating '\0' as a digit, and adds a regression test to numeric.sql
> (the test fails without the fix). make check passes (239/239) on
> master 45fc51fcbf45.
> Tom, CCing you since this became visible with ec352b37d.

That's definitely a bug, but on what basis do you say that it
wasn't visible before ec352b37d? AFAICT it's ancient.
I get this as far back as 9.2, for instance:

regression=# select to_char(7, 'FM99.SG') AS d;
d
---
7
(1 row)

Normally I'd think we should back-patch, but it's possible that
people didn't realize this behavior was unintended --- else we'd
have heard bug reports sooner. (It's not instantly obvious that
we should drop the decimal point but not the sign, I think.)
So I'm inclined to leave the stable branches alone. Maybe there's
still room to squeeze the fix into v19, though.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-10-19 02:43:03 Re: BUG #19763: ManualBug2 NULL pointer dereference in make_build_data via examine_expression bypass of lookup_var_a
Previous Message PG Bug reporting form 2026-10-18 23:22:05 BUG #19772: ERROR: corrupt MVNDistinct entry for GROUP BY c0, ROLLUP (abs(c0)) with ndistinct statistics