mdbx: корректировка osal_vasprintf() для устранения предупреждений статических анализаторов.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2023-03-28 21:40:15 +03:00
parent 74256efc64
commit caddf07889

View File

@ -316,17 +316,16 @@ MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt,
va_list ap) {
va_list ones;
va_copy(ones, ap);
int needed = vsnprintf(nullptr, 0, fmt, ap);
const int needed = vsnprintf(nullptr, 0, fmt, ones);
va_end(ones);
if (unlikely(needed < 0 || needed >= INT_MAX)) {
*strp = nullptr;
va_end(ones);
return needed;
}
*strp = osal_malloc(needed + (size_t)1);
if (unlikely(*strp == nullptr)) {
va_end(ones);
#if defined(_WIN32) || defined(_WIN64)
SetLastError(MDBX_ENOMEM);
#else
@ -335,9 +334,7 @@ MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt,
return -1;
}
int actual = vsnprintf(*strp, needed + (size_t)1, fmt, ones);
va_end(ones);
const int actual = vsnprintf(*strp, needed + (size_t)1, fmt, ap);
assert(actual == needed);
if (unlikely(actual < 0)) {
osal_free(*strp);
@ -351,7 +348,7 @@ MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt,
MDBX_INTERNAL_FUNC int osal_asprintf(char **strp, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int rc = osal_vasprintf(strp, fmt, ap);
const int rc = osal_vasprintf(strp, fmt, ap);
va_end(ap);
return rc;
}