forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3779ac6
committed
Make printf("%s", NULL) print "(null)" instead of crashing.
We previously took a hard-line attitude that callers should never printa null string pointer, and doing so is worthy of an assertion failureor crash. However, we've long since flushed out any easy-to-find bugsof that nature. What remains is a lot of code that perhaps could failthat way in hard-to-reach corner cases. For example, in something assimple as ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("constraint \"%s\" for table \"%s\" does not exist", conname, get_rel_name(relid))));one must wonder whether it's completely guaranteed that get_rel_namecannot return NULL in this context. If such a situation did occur,the existing policy converts what might be a pretty minor bug intoa server crash condition. This is not good for robustness.Hence, let's follow the lead of glibc and print "(null)" insteadof failing. We should, of course, still consider it a bug if thatbehavior is reachable in ordinary use; but crashing seems lessdesirable than not crashing.This fix works across-the-board in v12 and up, where we always usesrc/port/snprintf.c. Before that, on most platforms we're at the mercyof the local libc, but it appears that Solaris 10 is the only supportedplatform where we'd still get a crash. Most other platforms such as*BSD, macOS, and Solaris 11 have adopted glibc's behavior at somepoint. (AIX and HPUX just print "" not "(null)", but that's closeenough.) I've not checked what Windows' native printf would do, butit doesn't matter because we've long used snprintf.c on that platform.In v12 and up, also const-ify related code so that we're not castingaway const on the constant string. This is just neatnik-ism, sincenext to no compilers will warn about that.Discussion:https://postgr.es/m/17098-b960f3616c861f83@postgresql.org1 parent76fa3db commit3779ac6
1 file changed
+9
-7
lines changedLines changed: 9 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
320 | 320 |
| |
321 | 321 |
| |
322 | 322 |
| |
323 |
| - | |
| 323 | + | |
324 | 324 |
| |
325 | 325 |
| |
326 | 326 |
| |
| |||
394 | 394 |
| |
395 | 395 |
| |
396 | 396 |
| |
397 |
| - | |
| 397 | + | |
398 | 398 |
| |
399 | 399 |
| |
400 | 400 |
| |
| |||
439 | 439 |
| |
440 | 440 |
| |
441 | 441 |
| |
442 |
| - | |
| 442 | + | |
| 443 | + | |
443 | 444 |
| |
444 | 445 |
| |
445 | 446 |
| |
| |||
670 | 671 |
| |
671 | 672 |
| |
672 | 673 |
| |
673 |
| - | |
674 |
| - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
675 | 677 |
| |
676 | 678 |
| |
677 | 679 |
| |
| |||
681 | 683 |
| |
682 | 684 |
| |
683 | 685 |
| |
684 |
| - | |
| 686 | + | |
685 | 687 |
| |
686 | 688 |
| |
687 | 689 |
| |
| |||
995 | 997 |
| |
996 | 998 |
| |
997 | 999 |
| |
998 |
| - | |
| 1000 | + | |
999 | 1001 |
| |
1000 | 1002 |
| |
1001 | 1003 |
| |
|
0 commit comments
Comments
(0)