CM_SetField() and CM_SetAsField() now accept -1 as a length to have the function...
authorArt Cancro <ajc@citadel.org>
Tue, 10 Nov 2020 05:39:36 +0000 (00:39 -0500)
committerArt Cancro <ajc@citadel.org>
Tue, 10 Nov 2020 05:39:36 +0000 (00:39 -0500)
citadel/msgbase.c

index ae745958bc7c3b4a7106286d93fa2e3d27dff1e4..0bc88bf08f3f08243e3ca6af3d01eec54b835e32 100644 (file)
@@ -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;
+       }
 }