blob: Constify name argument of blob_get_def_by_name().
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 8 Mar 2022 22:05:52 +0000 (23:05 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Oct 2022 18:36:21 +0000 (20:36 +0200)
This function does not modify the string, although the char pointer
is used as the ->data pointer of an osl object, which is non-constant.

We need to cast away the const qualifier to avoid a compiler warning,
but that's still better than accepting only non-constant strings,
as this means to put the cast into the callers.

afs.h
blob.c

diff --git a/afs.h b/afs.h
index 43eb8f75855bb7082079194e0a32271e2ff9bf59..fb3a4f26015def92762069e39804561b4e05acfb 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -277,7 +277,7 @@ int playlist_check_callback(struct afs_callback_arg *aca);
        void table_name ## _init(struct afs_table *t); \
        int cmd_prefix ## _get_name_by_id(uint32_t id, char **name); \
        int cmd_prefix ## _get_def_by_id(uint32_t id, struct osl_object *def); \
-       int cmd_prefix ## _get_def_by_name(char *name, struct osl_object *def); \
+       int cmd_prefix ## _get_def_by_name(const char *name, struct osl_object *def); \
        int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
                char **name, struct osl_object *def); \
        int table_name ##_event_handler(enum afs_events event, \
diff --git a/blob.c b/blob.c
index b63724014138513dfb89d4300cb38056bfaa601a..eb9ccabacad41ea39a3c1a7b391e35f351a48ce4 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -520,11 +520,11 @@ static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
                return blob_get_name_by_id(table_name ## _table, id, name); \
        }
 
-static int blob_get_def_by_name(struct osl_table *table, char *name,
+static int blob_get_def_by_name(struct osl_table *table, const char *name,
                struct osl_object *def)
 {
        struct osl_row *row;
-       struct osl_object obj = {.data = name, .size = strlen(name) + 1};
+       struct osl_object obj = {.data = (void *)name, .size = strlen(name) + 1};
        int ret;
 
        def->data = NULL;
@@ -538,7 +538,7 @@ static int blob_get_def_by_name(struct osl_table *table, char *name,
 
 /** Define the \p get_def_by_id function for this blob type. */
 #define DEFINE_GET_DEF_BY_NAME(table_name, cmd_prefix) \
-       int cmd_prefix ## _get_def_by_name(char *name, struct osl_object *def) \
+       int cmd_prefix ## _get_def_by_name(const char *name, struct osl_object *def) \
        { \
                return blob_get_def_by_name(table_name ## _table, name, def); \
        }