]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make more dict functions take const
authorAlan T. DeKok <aland@freeradius.org>
Tue, 5 Nov 2019 14:25:19 +0000 (09:25 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 5 Nov 2019 14:35:27 +0000 (09:35 -0500)
the caller isn't supposed to modify them, but the dict code
can.

src/lib/util/dict.h
src/lib/util/dict_tokenize.c
src/lib/util/dict_util.c

index b93cde3e78eceee1b93d8fa062bc8734190d2578..cbb8a7b2d03cb24eaf30d6786f633a87357aaf80 100644 (file)
@@ -245,7 +245,7 @@ extern bool const   fr_dict_non_data_types[FR_TYPE_MAX + 1];
  *
  * @{
  */
-int                    fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, int attr,
+int                    fr_dict_attr_add(fr_dict_t const *dict, fr_dict_attr_t const *parent, char const *name, int attr,
                                         fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1,2,3));
 
 int                    fr_dict_enum_add_alias(fr_dict_attr_t const *da, char const *alias,
@@ -394,7 +394,7 @@ int                 fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name);
 
 int                    fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir);
 
-int                    fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename);
+int                    fr_dict_read(fr_dict_t const *dict, char const *dict_dir, char const *filename);
 /** @} */
 
 /** @name Autoloader interface
index 017587f94ae52fd20e3c83c96c17a732517d7865..95edf7650ad34f00ba486df0ebc93d979836e00d 100644 (file)
@@ -2401,8 +2401,9 @@ int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char co
  *     - 0 on success.
  *      - -1 on failure.
  */
-int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename)
+int fr_dict_read(fr_dict_t const *dict, char const *dir, char const *filename)
 {
+       fr_dict_t *mutable;
        INTERNAL_IF_NULL(dict, -1);
 
        if (!dict->attributes_by_name) {
@@ -2410,7 +2411,8 @@ int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename)
                return -1;
        }
 
-       return dict_from_file(dict, dir, filename, NULL, 0);
+       memcpy(&mutable, &dict, sizeof(dict));
+       return dict_from_file(mutable, dir, filename, NULL, 0);
 }
 
 /*
index a7fe0854fa608bd18fc142a40653e87a4cecdf4f..833de6a487742aab0527318b044672686e310939 100644 (file)
@@ -851,7 +851,7 @@ int dict_attr_add_by_name(fr_dict_t *dict, fr_dict_attr_t *da)
 
 /** Add an attribute to the dictionary
  *
- * @param[in] dict             of protocol context we're operating in.
+ * @param[in] const_dict               of protocol context we're operating in.
  *                             If NULL the internal dictionary will be used.
  * @param[in] parent           to add attribute under.
  * @param[in] name             of the attribute.
@@ -862,13 +862,16 @@ int dict_attr_add_by_name(fr_dict_t *dict, fr_dict_attr_t *da)
  *     - 0 on success.
  *     - -1 on failure.
  */
-int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent,
+int fr_dict_attr_add(fr_dict_t const *const_dict, fr_dict_attr_t const *parent,
                     char const *name, int attr, fr_type_t type, fr_dict_attr_flags_t const *flags)
 {
        fr_dict_attr_t          *n;
        fr_dict_attr_t const    *old;
        fr_dict_attr_t          *mutable;
        fr_dict_attr_flags_t    our_flags = *flags;
+       fr_dict_t               *dict;
+
+       memcpy(&dict, &const_dict, sizeof(const_dict)); /* const issues */
 
        /*
         *      Check that the definition is valid.
@@ -2355,14 +2358,17 @@ int fr_dict_autoload(fr_dict_autoload_t const *to_load)
  */
 void fr_dict_autofree(fr_dict_autoload_t const *to_free)
 {
-       fr_dict_t                       **dict;
+       fr_dict_t const                 **dict;
        fr_dict_autoload_t const        *p;
 
        for (p = to_free; p->out; p++) {
+               fr_dict_t **mutable;
                dict = p->out;
                if (!*dict) continue;
 
-               fr_dict_free(dict);
+               memcpy(&mutable, &dict, sizeof(dict)); /* const issues */
+
+               fr_dict_free(mutable);
        }
 }