From: Nathan Wagner Date: Wed, 7 Nov 2018 04:05:20 +0000 (+0000) Subject: fix printf formatting X-Git-Tag: v0.2.16~25 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=7d653379a303616ad009f67d238bf88278ea10bc fix printf formatting --- diff --git a/lib/script_hash.c b/lib/script_hash.c index 8348b02..67a167c 100644 --- a/lib/script_hash.c +++ b/lib/script_hash.c @@ -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; }