From: markus schnalke Date: Thu, 12 Nov 2015 16:03:36 +0000 (+0100) Subject: m_getfld2: Return line for LENERR2, plus some documentation X-Git-Tag: mmh-0.3~39^2~15 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=c4de1023b3141b9a89038012b246fa74205752cd;p=mmh m_getfld2: Return line for LENERR2, plus some documentation --- diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index 5920425..6d96bdd 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -26,8 +26,18 @@ static size_t copyname(char *, char *); /* -** For the states FLD2, BODY2 and FMTERR2 memory is allocated for f->value. -** For the states LENERR2, IOERR2 and FILEEOF2 no memory is allocated. +** FLD2: We read a (complete) header field +** BODY2: We read a body line +** LENERR2: Line is too long (>998, as defined by RFC 822) +** FMTERR2: Header field invalid +** IOERR2: Failure to read +** FILEEOF2: We're at the end of the file +** +** f->name is only filled in FLD2. +** +** In FLD2, f->value contains the field's (complete) value only; +** in BODY2, LENERR2 and FMTERR2 f->value contains the whole line; +** in IOERR2 and FILEEOF2 f->value is not set. */ enum state m_getfld2(enum state s, struct field *f, FILE *msg) @@ -46,14 +56,18 @@ m_getfld2(enum state s, struct field *f, FILE *msg) } } + *f->name = '\0'; + f->namelen = 0; + if (nchars >= NAMESZ) { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; return LENERR2; } - *f->name = '\0'; - f->namelen = 0; - switch (s) { case FLD2: if (*(tmpline + nchars - 1) != '\n') { @@ -99,7 +113,11 @@ m_getfld2(enum state s, struct field *f, FILE *msg) } if (nchars >= NAMESZ) { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; return LENERR2; }