X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Fm_getfld2.c;h=488a445cd0da0aa59d54130f36d8c530b20d5863;hb=2a903a43ad7d26f5581d4ad1bbc077f8ecc5f5a9;hp=74d25e4e9e03ec3f699a4f2c8ab5d44a23a8d745;hpb=02ad941fcb6ccc24fab97dff24a8f5253ab7e538;p=mmh diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index 74d25e4..488a445 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -10,7 +10,6 @@ #include #include #include -#include enum threestate { @@ -24,9 +23,7 @@ enum threestate { */ static enum threestate is_falted(FILE *); static size_t copyname(char *, char *); -static bool is_separator(char *); - -struct field free_field = { "\0", 0, NULL, 0, 0 }; +static boolean is_separator(char *); /* @@ -57,7 +54,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) nchars = getline(&tmpline, &len, msg); if (nchars < 1) { free(f->value); - *f = free_field; + *f = (struct field) { "\0", 0, NULL, 0, 0 }; if (feof(msg)) { return FILEEOF2; } else { @@ -99,17 +96,13 @@ m_getfld2(enum state s, struct field *f, FILE *msg) f->valuelen = nchars; } - while (ret == FLD2 && (falted = is_falted(msg)) == B_TRUE) { + while ((ret == FLD2 || ret == LENERR2) && (falted = is_falted(msg)) == B_TRUE) { nchars = getline(&tmpline, &len, msg); if (nchars <= 0) { free(tmpline); return IOERR2; } - if (nchars >= NAMESZ) { - ret = LENERR2; - } - if (*(tmpline + nchars - 1) != '\n') { ret = FMTERR2; } @@ -132,12 +125,15 @@ m_getfld2(enum state s, struct field *f, FILE *msg) return ret; case BODY2: - free(f->value); - *f = free_field; + *f->name = '\0'; + f->namelen = 0; nchars = getline(&tmpline, &len, msg); if (nchars < 1) { - free(tmpline); + free(f->value); + f->value = NULL; + f->valuelen = 0; + f->alloclen = 0; if (feof(msg)) { return FILEEOF2; } else { @@ -149,6 +145,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) ret = LENERR2; } + free(f->value); f->value = tmpline; f->valuelen = nchars; f->alloclen = len; @@ -212,7 +209,7 @@ copyname(char *dst, char *src) return strlen(dst); } -static bool +static boolean is_separator(char *line) { /* @@ -223,7 +220,7 @@ is_separator(char *line) line++; } if (strcmp("\n", line) == 0 || strcmp("\r\n", line) == 0 ) { - return true; + return TRUE; } - return false; + return FALSE; }