From e052c7991c00263bcf20f033e95f15e3bbdcc8ca Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Thu, 30 Apr 2020 13:20:41 -0500 Subject: [PATCH] settings: add const qualifier for unmodified data source Code using this API to set a key to a value that is a string literal produces errors in C++ because the passed pointer is not const qualified, allowing the possibility that the callee modifies the referenced string literal memory. Add the required const qualifiers since the set function does not change the passed to it. Signed-off-by: Peter Bigot --- include/settings/settings.h | 2 +- subsys/settings/src/settings_runtime.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/settings/settings.h b/include/settings/settings.h index d7d8b52d5c5..2874227fad6 100644 --- a/include/settings/settings.h +++ b/include/settings/settings.h @@ -567,7 +567,7 @@ int settings_name_next(const char *name, const char **next); * * @return 0 on success, non-zero on failure. */ -int settings_runtime_set(const char *name, void *data, size_t len); +int settings_runtime_set(const char *name, const void *data, size_t len); /** * Get a value corresponding to a key from a module handler. diff --git a/subsys/settings/src/settings_runtime.c b/subsys/settings/src/settings_runtime.c index 6aa1e45c8bf..bfed1323e88 100644 --- a/subsys/settings/src/settings_runtime.c +++ b/subsys/settings/src/settings_runtime.c @@ -11,7 +11,7 @@ #include "settings_priv.h" struct read_cb_arg { - void *data; + const void *data; size_t len; }; @@ -23,7 +23,7 @@ static ssize_t settings_runtime_read_cb(void *cb_arg, void *data, size_t len) return MIN(arg->len, len); } -int settings_runtime_set(const char *name, void *data, size_t len) +int settings_runtime_set(const char *name, const void *data, size_t len) { struct settings_handler_static *ch; const char *name_key;