From 0f664765324ab276cad2d1f1e14ae64c81def413 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 8 Mar 2022 23:05:52 +0100 Subject: [PATCH] blob: Constify name argument of blob_get_def_by_name(). 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 | 2 +- blob.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/afs.h b/afs.h index 43eb8f75..fb3a4f26 100644 --- 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 b6372401..eb9ccaba 100644 --- 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); \ } -- 2.39.2