Don't pass NULL to fprintf, if not currently connected to a database.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 15 Jan 2013 16:54:03 +0000 (18:54 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 15 Jan 2013 17:20:15 +0000 (19:20 +0200)
Backpatch all the way to 8.3. Fixes bug #7811, per report and diagnosis by
Meng Qingzhong.

src/bin/psql/help.c

index 717d4cd10cfb9d064bd3151926f6c1f5bb6c1482..58f8a0b0167522dd8a0f13666c2d900bb843246e 100644 (file)
@@ -161,6 +161,11 @@ void
 slashUsage(unsigned short int pager)
 {
        FILE       *output;
+       char       *currdb;
+
+       currdb = PQdb(pset.db);
+       if (currdb == NULL)
+               currdb = _("none");
 
        output = PageOutput(94, pager);
 
@@ -253,7 +258,7 @@ slashUsage(unsigned short int pager)
        fprintf(output, _("Connection\n"));
        fprintf(output, _("  \\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]\n"
        "                         connect to new database (currently \"%s\")\n"),
-                       PQdb(pset.db));
+                       currdb);
        fprintf(output, _("  \\encoding [ENCODING]   show or set client encoding\n"));
        fprintf(output, _("  \\password [USERNAME]   securely change the password for a user\n"));
        fprintf(output, _("  \\conninfo              display information about current connection\n"));