From: | Nicolai Tufar <ntufar(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Joerg Hessdoerfer <Joerg(dot)Hessdoerfer(at)sea-gmbh(dot)com>, Magnus Hagander <mha(at)sollentuna(dot)net>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-hackers-win32(at)postgresql(dot)org |
Subject: | Re: [HACKERS] snprintf causes regression tests to fail |
Date: | 2005-03-01 23:37:56 |
Message-ID: | d8092939050301153749cb3bea@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-hackers-win32 |
On Tue, 01 Mar 2005 18:15:49 -0500, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Nicolai Tufar <ntufar(at)gmail(dot)com> writes:
> >> Having looked at the current snprintf.c, I don't actually believe that
> >> it works at all in the presence of positional parameter specs.
>
> > It picks up arguments in order of appearance, places them in
> > array then shuffles them according to %n$ positional parameter.
> > I checked it with in many different combinations, it works!
>
> 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.
> You cannot pick this up in order of appearance and expect it to work.
> It might fail to fail on some machine architectures, but it's not going
> to be portable.
I did not modify the code that picked up the values.
I just modified it to instead of passing to printing function
store values in array.
> >> On the other side of the
> >> coin, the hardwired 4K limit in printf() is certainly *not* enough.
>
> > How would one solve this issue. Calling malloc() from a print function
> > would be rather expensive.
>
> printf shouldn't use a buffer at all. I was thinking in terms of
> passing around a state struct like
>
> typedef struct {
> char *output;
> char *end;
> FILE *outfile;
> } printf_target;
>
> and making dopr_outch look like
>
> static void
> dopr_outch(int c, printf_target *state)
> {
> if (state->output)
> {
> if (state->end == NULL || state->output < state->end)
> *(state->output++) = c;
> }
> else
> fputc(c, state->outfile);
> }
I will consider it tomorrow. It is too late on this side of
the pond, I need to sleep. Thank you for your attention
and help.
best regards,
Nicolai Tufar
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-03-01 23:53:43 | Re: [HACKERS] snprintf causes regression tests to fail |
Previous Message | Thomas F.O'Connell | 2005-03-01 23:23:52 | Re: Where to see the patch queue (was Re: [PATCHES] Patch |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-03-01 23:53:43 | Re: [HACKERS] snprintf causes regression tests to fail |
Previous Message | Tom Lane | 2005-03-01 23:15:49 | Re: [HACKERS] snprintf causes regression tests to fail |