[GNUPG HEAD] sqlite3 compatibility issue

Ineiev ineiev at gnu.org
Thu May 18 14:50:21 CEST 2017


Hello,

GnuPG doesn't build with sqlite 3.7.9 because it has
no sqlite3_errstr ().  I wonder if it could be worked around like

diff --git a/g10/gpgsql.c b/g10/gpgsql.c
index 5b75569..3bade5c 100644
--- a/g10/gpgsql.c
+++ b/g10/gpgsql.c
@@ -64,7 +64,8 @@ gpgsql_stepx (sqlite3 *db,
               const char *sql, ...)
 {
   int rc;
-  int err = 0;
+  int err = SQLITE_OK;
+  const char *errstr = NULL;
   sqlite3_stmt *stmt = NULL;
 
   va_list va;
@@ -161,7 +162,7 @@ gpgsql_stepx (sqlite3 *db,
               log_fatal ("Bad value for parameter type %d.\n", t);
             }
 
-          if (err)
+          if (err != SQLITE_OK)
             {
               log_fatal ("Error binding parameter %d\n", i);
               goto out;
@@ -203,6 +204,7 @@ gpgsql_stepx (sqlite3 *db,
             /* Out of memory.  */
             {
               err = SQLITE_NOMEM;
+              errstr = "out of memory";
               break;
             }
         }
@@ -211,6 +213,7 @@ gpgsql_stepx (sqlite3 *db,
         /* A non-zero result means to abort.  */
         {
           err = SQLITE_ABORT;
+          errstr = "callback requested query abort";
           break;
         }
     }
@@ -218,33 +221,26 @@ gpgsql_stepx (sqlite3 *db,
  out:
   xfree (azColName);
 
+  if (err != SQLITE_OK && errmsg && !errstr)
+    errstr = sqlite3_errmsg (db);
+
   if (stmtp)
     rc = sqlite3_reset (stmt);
   else
     rc = sqlite3_finalize (stmt);
-  if (rc == SQLITE_OK && err)
-    /* Local error.  */
-    {
-      rc = err;
-      if (errmsg)
-        {
-          const char *e = sqlite3_errstr (err);
-          size_t l = strlen (e) + 1;
-          *errmsg = sqlite3_malloc (l);
-          if (! *errmsg)
-            log_fatal ("Out of memory.\n");
-          memcpy (*errmsg, e, l);
-        }
-    }
-  else if (rc != SQLITE_OK && errmsg)
-    /* Error reported by sqlite.  */
+
+  if (rc != SQLITE_OK)
+    errstr = sqlite3_errmsg (db);
+  else
+    rc = err;
+
+  if (rc != SQLITE_OK && errmsg)
     {
-      const char * e = sqlite3_errmsg (db);
-      size_t l = strlen (e) + 1;
+      size_t l = strlen (errstr) + 1;
       *errmsg = sqlite3_malloc (l);
       if (! *errmsg)
         log_fatal ("Out of memory.\n");
-      memcpy (*errmsg, e, l);
+      memcpy (*errmsg, errstr, l);
     }
 
   return rc;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: Digital signature
URL: </pipermail/attachments/20170518/9a71c5e6/attachment.sig>


More information about the Gnupg-devel mailing list