Fix our printf implementation to follow spec: if a star parameter
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Mar 2008 01:49:44 +0000 (01:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Mar 2008 01:49:44 +0000 (01:49 +0000)
value for a precision is negative, act as though precision weren't
specified at all, that is the whole .* part of the format spec should
be ignored.  Our previous coding took it as .0 which is certainly
wrong.  Per report from Kris Jurka and local testing.

Possibly this should be back-patched, but it would be good to get
some more testing first; in any case there are no known cases where
there's really a problem on the backend side.

src/port/snprintf.c

index e6323e6937d25bfbb7f2701bcce1fc2c1482c9ea..66f3d5df868f3f5f105b649b1a8037d5bb8f83d6 100644 (file)
@@ -565,7 +565,10 @@ nextch2:
                                        {
                                                precision = starval;
                                                if (precision < 0)
+                                               {
                                                        precision = 0;
+                                                       pointflag = 0;
+                                               }
                                        }
                                        else
                                        {
@@ -590,7 +593,10 @@ nextch2:
                                        {
                                                precision = starval;
                                                if (precision < 0)
+                                               {
                                                        precision = 0;
+                                                       pointflag = 0;
+                                               }
                                        }
                                        else
                                        {