summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-16 17:07:41 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-16 18:37:07 +0100
commitcf4bcc3f1435eafa3ed8b5fadfa9698033d1e2df (patch)
tree34b2cdc750ce7a51b7ee2a58f2d076e99d294f52 /utils.c
parent1724ae7c21a6840a402a685ceea7f3366788a516 (diff)
Also add const qualifiers on server side
Although in practice the buffers can be modified since they are from the message, it leads to missing const where it would otherwise make sense.
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/utils.c b/utils.c
index 5111e73..48c4420 100644
--- a/utils.c
+++ b/utils.c
@@ -182,13 +182,42 @@ WriteUserVarDecl(FILE *file, const argument_t *arg)
fprintf(file, "\t%s%s %s%s", qualif, arg->argType->itUserType, ref, arg->argVarName);
}
+/* Returns whether parameter should be qualified with const because we will only
+ receive the pointed data, not modify it. */
+static boolean_t
+ServerVarConst(const argument_t *arg)
+{
+ return (arg->argKind & (akbSend|akbReturn)) == akbSend
+ && !arg->argType->itStruct;
+}
+
+const char *
+ServerVarQualifier(const argument_t *arg)
+{
+ if (!ServerVarConst(arg))
+ return "";
+
+ if (arg->argType->itIndefinite ||
+ arg->argType->itInName == MACH_MSG_TYPE_STRING_C ||
+ !strcmp(arg->argType->itTransType, "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 ";
+}
+
void
WriteServerVarDecl(FILE *file, const argument_t *arg)
{
+ const char *qualif = ServerVarQualifier(arg);
const char *ref = arg->argByReferenceServer ? "*" : "";
- fprintf(file, "\t%s %s%s",
- arg->argType->itTransType, ref, arg->argVarName);
+ fprintf(file, "\t%s%s %s%s",
+ qualif, arg->argType->itTransType, ref, arg->argVarName);
}
void