Greg Ward avatar Greg Ward committed 518954f

svn: check return value of *every* *single* SQLite call that can fail

Comments (0)

Files changed (1)

     // unclear when wc_id is anything other than 1
     char *sql = ("select changed_revision from nodes "
                  "where wc_id = 1 and local_relpath = ''");
-    retval = sqlite3_prepare_v2(conn, sql, 1000, &res, &tail);
+    const char *textval;
+    retval = sqlite3_prepare_v2(conn, sql, strlen(sql), &res, &tail);
     if (retval != SQLITE_OK) {
         debug("error running query: %s", sqlite3_errstr(retval));
         goto err;
     }
-    char *buf = malloc(1024);
     retval = sqlite3_step(res);
     if (retval != SQLITE_DONE && retval != SQLITE_ROW) {
         debug("error fetching result row");
         goto err;
     }
-    sprintf(buf, "%s", sqlite3_column_text(res, 0));
-    result->revision = buf;
+    textval = (const char *) sqlite3_column_text(res, 0);
+    if (textval == NULL) {
+        debug("could not retrieve value of nodes.changed_revision");
+        goto err;
+    }
+    result->revision = strdup(textval);
     sqlite3_finalize(res);
 
     sql = "select repos_path from nodes where local_relpath = ?";
         goto err;
     }
 
-    repos_path = strdup((const char *) sqlite3_column_text(res, 0));
+    textval = (const char *) sqlite3_column_text(res, 0);
+    if (textval == NULL) {
+        debug("could not retrieve value of nodes.repos_path");
+        goto err;
+    }
+    repos_path = strdup(textval);
     result->branch = get_branch_name(repos_path);
 
     ok = 1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.