Through the rest of the file, the data member of struct msg_data is
kept NUL-terminated, and that fact is relied upon in a couple of
places. Change lf_to_crlf() to preserve this invariant.
In fact, there are no execution paths in which lf_to_crlf() is called
and then its data member is required to be NUL-terminated, but it is
better to be consistent to prevent future confusion.
Document the invariant in the struct msg_data definition.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
};
struct msg_data {
+ /* NUL-terminated data: */
char *data;
+
+ /* length of data (not including NUL): */
int len;
+
unsigned char flags;
};
lfnum++;
}
- new = xmalloc(msg->len + lfnum);
+ new = xmalloc(msg->len + lfnum + 1);
if (msg->data[0] == '\n') {
new[0] = '\r';
new[1] = '\n';
/* otherwise it already had CR before */
new[j++] = '\n';
}
+ new[j] = '\0';
msg->len += lfnum;
free(msg->data);
msg->data = new;