From: markus schnalke Date: Tue, 10 Nov 2015 19:58:31 +0000 (+0100) Subject: Return invalid line for FMTERR in m_getfld2() X-Git-Tag: mmh-0.3~39^2~19 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=f5df6f250dc5862488efb0198823c68f5b573ccc;p=mmh Return invalid line for FMTERR in m_getfld2() This is necessary for mbox handling outside of m_getfld2(). --- diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index 6eb0ef8..91164f3 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -26,8 +26,8 @@ static size_t copyname(char *, char *); /* -** For the states FLD2, BODY2 memory is allocated for f->value. -** For the states LENERR2, FMTERR2, ERR2 and FILEEOF2 no memory is allocated. +** For the states FLD2, BODY2 and FMTERR2 memory is allocated for f->value. +** For the states LENERR2, ERR2 and FILEEOF2 no memory is allocated. */ enum state m_getfld2(enum state s, struct field *f, FILE *msg) @@ -51,10 +51,18 @@ m_getfld2(enum state s, struct field *f, FILE *msg) return LENERR2; } + *f->name = '\0'; + f->namelen = 0; + switch (s) { case FLD2: if (*(tmpline + nchars - 1) != '\n') { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; + f->alloclen = len; return FMTERR2; } @@ -66,7 +74,12 @@ m_getfld2(enum state s, struct field *f, FILE *msg) f->namelen = copyname(f->name, tmpline); if (f->namelen < 1) { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; + f->alloclen = len; return FMTERR2; } @@ -91,7 +104,12 @@ m_getfld2(enum state s, struct field *f, FILE *msg) } if (*(tmpline + nchars - 1) != '\n') { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; + f->alloclen = len; return FMTERR2; } @@ -114,8 +132,6 @@ m_getfld2(enum state s, struct field *f, FILE *msg) return FLD2; case BODY2: - *f->name = '\0'; - f->namelen = 0; if (f->value) { free(f->value); }