]> pd.if.org Git - zpackage/commitdiff
fix printf formatting
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 7 Nov 2018 04:05:20 +0000 (04:05 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Wed, 7 Nov 2018 04:05:20 +0000 (04:05 +0000)
lib/script_hash.c

index 8348b0247c4c2073d3b2794e83089135c8e21998..67a167cad1fb777cc667ede7c24d3f90087ffc63 100644 (file)
@@ -14,8 +14,8 @@ int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
        sqlite3_str *s;
        sqlite3_stmt *st;
 
-       char *find = "select printf('%s-%s-%d', package, version, release) as pkgid, stage, hash from scripts where true";
-       char *pkgidwhere = " and printf('%s-%s-%d', package, version, release) = %Q";
+       char *find = "select printf('%%s-%%s-%%d', package, version, release) as pkgid, stage, hash from scripts where true";
+       char *pkgidwhere = " and printf('%%%%s-%%%%s-%%%%d', package, version, release) = %Q";
        char *stagewhere = " and stage = %Q";
 
        if (!zpm || !cb) {
@@ -43,9 +43,8 @@ int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
                sqlite3_str_appendf(s, stagewhere, stage);
        }
 
-       sql = sqlite3_str_value(s);
+       sql = sqlite3_str_finish(s);
        if (!sql) {
-               sqlite3_str_finish(s);
                zpm->error = 1;
                if (pkgid) {
                        free(pkgid);
@@ -54,6 +53,13 @@ int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
        }
 
        st = zpm_dbquery(zpm, sql);
+
+       if (!st) {
+               zpm->error = 1;
+               sqlite3_free(sql);
+               return 0;
+       }
+
        int rv, cbrv = 0;
        while ((rv = sqlite3_step(st)) == SQLITE_ROW) {
                if (cb) {
@@ -80,6 +86,7 @@ int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
                free(pkgid);
        }
 
+       sqlite3_free(sql);
        return cbrv;
 }