From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no> |
Cc: | Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: function returning a row |
Date: | 2005-01-31 17:23:31 |
Message-ID: | 20648.1107192211@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no> writes:
> text *intext = PG_GETARG_TEXT_P(0);
> text *smltext = PG_GETARG_TEXT_P(1);
> in = (char*)palloc(VARSIZE(intext)-VARHDRSZ+1);
> sml = (char*)palloc(VARSIZE(smltext)-VARHDRSZ+1);
> snprintf (in, VARSIZE(intext) - VARHDRSZ + 1, VARDATA(intext));
> snprintf (sml, VARSIZE(smltext) - VARHDRSZ + 1, VARDATA(smltext));
I'm not sure what you think the above snprintf's are going to do, but
it seems certain to be bad. The "format string" you are passing is
neither null-terminated nor guaranteed to be free of %'s.
memcpy would be safer; and of course you need to explicitly append a
null byte afterwards.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Van Ingen, Lane | 2005-01-31 18:36:31 | Date / Time Data Type |
Previous Message | Kjetil Haaland | 2005-01-31 15:42:41 | Re: function returning a row |