[db] Faster size check in db.c's db_snprintf()

This commit is contained in:
ejurgensen 2017-10-14 13:17:21 +02:00
parent 47585d0d03
commit 659b5c70c4
1 changed files with 4 additions and 1 deletions

View File

@ -385,11 +385,14 @@ db_snprintf(char *s, int n, const char *fmt, ...)
if (n < 2) if (n < 2)
return -1; return -1;
// For size check since sqlite3_vsnprintf does not seem to support it
s[n - 2] = '\0';
va_start(va, fmt); va_start(va, fmt);
ret = sqlite3_vsnprintf(n, s, fmt, va); ret = sqlite3_vsnprintf(n, s, fmt, va);
va_end(va); va_end(va);
if (!ret || (strlen(ret) == n - 1)) if (!ret || (s[n - 2] != '\0'))
return -1; return -1;
return 0; return 0;