summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-11-30 23:57:11 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-11-30 23:57:11 +0100
commitb147427aa16309657856bd9ec6ef50c60b241e18 (patch)
treeb708fe6671953b311b9a891496970caa6d927999
parent88b859c0d1a377d584bda4fb74846ec19a7b958f (diff)
Make string_t always use const_string_t
This will allow to relieve constraints in callers, e.g. dir_lookup("") would otherwise produce a warning with gcc-11 since char[1024] would mean that dir_lookup would read all 1024 characters while it is not. * utils.c (UserVarQualifier): Also use const_ qualifier when type is string_t. * tests/includes/types.h (const_string_t): New type.
-rw-r--r--tests/includes/types.h1
-rw-r--r--utils.c10
2 files changed, 8 insertions, 3 deletions
diff --git a/tests/includes/types.h b/tests/includes/types.h
index 0bb914c..c8c3afd 100644
--- a/tests/includes/types.h
+++ b/tests/includes/types.h
@@ -29,6 +29,7 @@ typedef struct char_struct {
} char_struct_t;
typedef char* string_t;
+typedef const char* const_string_t;
static inline int8_t int_to_int8(int n) {
return (int8_t) n;
diff --git a/utils.c b/utils.c
index 4ddadc5..505f434 100644
--- a/utils.c
+++ b/utils.c
@@ -159,9 +159,13 @@ UserVarQualifier(const argument_t *arg)
if (!UserVarConst(arg))
return "";
- if (arg->argType->itIndefinite)
- /* This is a pointer type, so we have to use the const_foo type to
- make const qualify the data, not the pointer. */
+ if (arg->argType->itIndefinite ||
+ !strcmp(arg->argType->itUserType, "string_t"))
+ /* This is a pointer, so we have to use the const_foo type to
+ make const qualify the data, not the pointer.
+
+ Or this is a string_t, which should use const_string_t to avoid
+ forcing the caller to respect the definite string size */
return "const_";
else
return "const ";