From 7d653379a303616ad009f67d238bf88278ea10bc Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Wed, 7 Nov 2018 04:05:20 +0000 Subject: [PATCH] fix printf formatting --- lib/script_hash.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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; } -- 2.40.0