From 659b5c70c47fd21486a39c8179401e1a78defc3f Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sat, 14 Oct 2017 13:17:21 +0200 Subject: [PATCH] [db] Faster size check in db.c's db_snprintf() --- src/db.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index b58732d0..415efca9 100644 --- a/src/db.c +++ b/src/db.c @@ -385,11 +385,14 @@ db_snprintf(char *s, int n, const char *fmt, ...) if (n < 2) return -1; + // For size check since sqlite3_vsnprintf does not seem to support it + s[n - 2] = '\0'; + va_start(va, fmt); ret = sqlite3_vsnprintf(n, s, fmt, va); va_end(va); - if (!ret || (strlen(ret) == n - 1)) + if (!ret || (s[n - 2] != '\0')) return -1; return 0;