pgsql: Clean up dubious code in contrib/seg. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Clean up dubious code in contrib/seg.
Date
Msg-id E1amphh-0001rZ-Ve@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Clean up dubious code in contrib/seg.

The restore() function assumed that the result of sprintf() with %e format
would necessarily contain an 'e', which is false: what if the supplied
number is an infinity or NaN?  If that did happen, we'd get a
null-pointer-dereference core dump.  The case appears impossible currently,
because seg_in() does not accept such values, and there are no seg-creating
functions that would create one.  But it seems unwise to rely on it never
happening in future.

Quite aside from that, the code was pretty ugly: it relied on modifying a
static format string when it could use a "*" precision argument, and it
used strtok() entirely gratuitously, and it stripped off trailing spaces
by hand instead of just not asking for them to begin with.

Coverity noticed the potential null pointer dereference (though I wonder
why it didn't complain years ago, since this code is ancient).

Since this is just code cleanup and forestalling a hypothetical future
bug, there seems no need for back-patching.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/a75a418d07bf852dc9fdb85ccfb39c763aa057a9

Modified Files
--------------
contrib/seg/seg.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix contrib/bloom to not fail under CLOBBER_CACHE_ALWAYS.
Next
From: David Rowley
Date:
Subject: Re: pgsql: Copyedit comments and documentation.