X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;ds=sidebyside;f=sbr%2Fm_getfld2.c;h=59204252d7f8c5eec7305138825e097ca0e1c601;hb=a3d849510ecad775e265ab7b6090e85576f48ef7;hp=6eb0ef8c311491acd18b8e730e4523b4cff782e3;hpb=4e6362c1749f16f1b09fb04d5951a03c1d9aa9cd;p=mmh diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index 6eb0ef8..5920425 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, IOERR2 and FILEEOF2 no memory is allocated. */ enum state m_getfld2(enum state s, struct field *f, FILE *msg) @@ -42,7 +42,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) if (feof(msg)) { return FILEEOF2; } else { - return ERR2; + return IOERR2; } } @@ -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; } @@ -82,7 +95,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) nchars = getline(&tmpline, &len, msg); if (nchars <= 0) { free(tmpline); - return ERR2; + return IOERR2; } if (nchars >= NAMESZ) { @@ -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; } @@ -107,15 +125,13 @@ m_getfld2(enum state s, struct field *f, FILE *msg) if (falted == FAIL) { free(tmpline); - return ERR2; + return IOERR2; } free(tmpline); return FLD2; case BODY2: - *f->name = '\0'; - f->namelen = 0; if (f->value) { free(f->value); } @@ -159,11 +175,17 @@ static size_t copyname(char *dst, char *src) { size_t len; - char *sep = strchr(src, ':'); + char *cp, *sep; - if (!sep) { + if (!(sep = strchr(src, ':'))) { return 0; } + /* whitespace is forbidden in name */ + for (cp=src; cp= NAMESZ) {