From f72c1373a7376a3fb909995b32e45f828f9e3913 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 10 Nov 2020 00:39:36 -0500 Subject: [PATCH] CM_SetField() and CM_SetAsField() now accept -1 as a length to have the function measure the field for the caller. --- citadel/msgbase.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index ae745958b..0bc88bf08 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -149,6 +149,9 @@ void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long if (Msg->cm_fields[which] != NULL) { free (Msg->cm_fields[which]); } + if (length < 0) { // You can set the length to -1 to have CM_SetField measure it for you + length = strlen(buf); + } Msg->cm_fields[which] = malloc(length + 1); memcpy(Msg->cm_fields[which], buf, length); Msg->cm_fields[which][length] = '\0'; @@ -256,7 +259,12 @@ void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long le Msg->cm_fields[which] = *buf; *buf = NULL; - Msg->cm_lengths[which] = length; + if (length < 0) { // You can set the length to -1 to have CM_SetField measure it for you + Msg->cm_lengths[which] = strlen(buf); + } + else { + Msg->cm_lengths[which] = length; + } } -- 2.30.2