From: Art Cancro Date: Tue, 10 Nov 2020 05:39:36 +0000 (-0500) Subject: CM_SetField() and CM_SetAsField() now accept -1 as a length to have the function... X-Git-Tag: v939~229 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=f72c1373a7376a3fb909995b32e45f828f9e3913 CM_SetField() and CM_SetAsField() now accept -1 as a length to have the function measure the field for the caller. --- 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; + } }