[db] Faster size check in db.c's db_snprintf()
This commit is contained in:
parent
47585d0d03
commit
659b5c70c4
5
src/db.c
5
src/db.c
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue