]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
initialize buff to placate coverity (CIDs #1503942, #1504042) (#4738)
authorJames Jones <jejones3141@gmail.com>
Fri, 23 Sep 2022 11:45:02 +0000 (06:45 -0500)
committerGitHub <noreply@github.com>
Fri, 23 Sep 2022 11:45:02 +0000 (07:45 -0400)
Coverity doesn't realize that fr_sbuff_out_bstrncpy_allowed()
will put something in buff, if only a NUL terminator. Until
coverity sees annotations in macro definitions, the only way
I know of to avoid the false positive "uninit_use_in_call"
defects in SBUFF_PARSE_FLOAT_DEF()-generated functions is to
actually initialize buff.

src/lib/util/sbuff.c

index c7f26940dbfd1b63e82555e4f3a699b38b8e9571..223db6206e54e930fef87f79caea3bc133de380c 100644 (file)
@@ -1265,7 +1265,7 @@ SBUFF_PARSE_UINT_DEF(size_hex, size_t, SIZE_MAX, 22, 16)
 #define SBUFF_PARSE_FLOAT_DEF(_name, _type, _func, _max_char) \
 fr_slen_t fr_sbuff_out_##_name(fr_sbuff_parse_error_t *err, _type *out, fr_sbuff_t *in, bool no_trailing) \
 { \
-       char            buff[_max_char + 1]; \
+       char            buff[_max_char + 1] = ""; \
        char            *end; \
        fr_sbuff_t      our_in = FR_SBUFF(in); \
        size_t          len; \
@@ -1279,7 +1279,6 @@ fr_slen_t fr_sbuff_out_##_name(fr_sbuff_parse_error_t *err, _type *out, fr_sbuff
                return -1; \
        } \
        errno = 0; /* this is needed as parsing functions don't reset errno */ \
-       /* coverity[uninit_use_in_call] */ \
        res = _func(buff, &end); \
        if (errno == ERANGE) { \
                if (res > 0) { \