]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Attempt to placate coverity about fr_value_box_init() (CID #1508484)
authorJames Jones <jejones3141@gmail.com>
Wed, 21 Jun 2023 17:45:32 +0000 (12:45 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 22 Jun 2023 14:03:51 +0000 (10:03 -0400)
An fr_value_box_t has some members with const-qualified type. The
only way one can assign to it in this context is with an
initializer, which doesn't make sense here, hence the memcpy().
That makes the compilers happy, but coverity notices that
vp points at an fr_value_box_t and considers it a defect, even
though it's all we can do.

In a similar situation elsewhere, coverity notices a parameter
cast from void * to pointer to some structure type. It notices it,
calls it "downcasting" (odd for a non-OOP language) and
considers the allegedly pointed-at structure as tainted--perhaps
alignment issues? We'll attempt a cast to void *,  and see whether
coverity will notice how it started out and still complain.

src/lib/util/value.h

index 5afcab20675d73f5492a5ded21b1dbf650010309..880a57c08822fbce96b5b663bd69936b6b224784 100644 (file)
@@ -411,11 +411,11 @@ static inline CC_HINT(nonnull(1), always_inline)
 void fr_value_box_init(fr_value_box_t *vb, fr_type_t type, fr_dict_attr_t const *enumv, bool tainted)
 {
        /* coverity[store_writes_const_field] */
-       memcpy(vb, &(fr_value_box_t){
+       memcpy((void *) vb, &(fr_value_box_t){
                        .type = type,
                        .enumv = enumv,
                        .tainted = tainted
-              }, sizeof(*vb));
+               }, sizeof(*vb));
        fr_value_box_list_entry_init(vb);
 
        /*