Re: [HACKERS] snprintf causes regression tests to fail
Tom Lane <[email protected]>
| Newsgroups | gmane.comp.db.postgresql.devel.win32 |
|---|---|
| Message-ID | <[email protected]> |
Nicolai Tufar <[email protected]> writes: > On Tue, 01 Mar 2005 18:15:49 -0500, Tom Lane <[email protected]> wrote: >> Did you try combinations of parameters of different sizes? For instance >> >> snprintf(..., "%g %d", doubleval, intval); >> and >> snprintf(..., "%2$d %1$g", doubleval, intval); > It works perfectly fine. Just checked. Well, whatever architecture you're checking on may happen to make it work, but that does *not* mean it's portable. On my machine it fails: int main() { char buf[1000]; double d = 3.14159265358979; int i = 42; snprintf(buf, sizeof buf, "%.15g %d", d, i); printf("result = '%s'\n", buf); snprintf(buf, sizeof buf, "%2$d %1$.15g", d, i); printf("result = '%s'\n", buf); return 0; } "Correct" output with the system snprintf is result = '3.14159265358979 42' result = '42 3.14159265358979' With CVS-tip snprintf I get result = '3 42' result = '3 3505' The second value in the last line varies erratically from run to run, presumably because it's picking up garbage. This output appears to indicate some problems in passing around precision specs as well as the values themselves... regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [email protected] so that your message can get through to the mailing list cleanly