]> granicus.if.org Git - postgresql/commitdiff
Add an assertion that we don't pass NULL to snprintf("%s").
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Feb 2018 20:06:01 +0000 (15:06 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Feb 2018 20:06:01 +0000 (15:06 -0500)
Per commit e748e902d, we appear to have little or no coverage in the
buildfarm of machines that will dump core when asked to printf a
null string pointer.  Let's try to improve that situation by adding
an assertion that will make src/port/snprintf.c behave that way.
Since it's just an assertion, it won't break anything in production
builds, but it will help developers find this type of oversight.

Note that while our buildfarm coverage of machines that use that
snprintf implementation is pretty thin on the Unix side (apparently
amounting only to gaur/pademelon), all of the MSVC critters use it.

Discussion: https://postgr.es/m/156b989dbc6fe7c4d3223cf51da61195@postgrespro.ru

src/port/snprintf.c

index 43c17e702e2022d1659b2ab040f16aecacedb34b..83584259802348dc506a008b5713ae7b045b8f3a 100644 (file)
@@ -745,6 +745,8 @@ nextch2:
                                        strvalue = argvalues[fmtpos].cptr;
                                else
                                        strvalue = va_arg(args, char *);
+                               /* Whine if someone tries to print a NULL string */
+                               Assert(strvalue != NULL);
                                fmtstr(strvalue, leftjust, fieldwidth, precision, pointflag,
                                           target);
                                break;