X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/04fa4f414a9d257104bcf6c20372e603865dfb42..2194825961eefdab538204e3bb682825a5427e14:/sbr/m_getfld.c diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 07f4c0a5..63b3fda2 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -313,7 +313,10 @@ void m_getfld_state_destroy (m_getfld_state_t *gstate) { m_getfld_state_t s = *gstate; if (s) { - if (s->fdelim) free (s->fdelim-1); + if (s->fdelim) { + free (s->fdelim-1); + free (s->pat_map); + } free (s); *gstate = 0; } @@ -627,12 +630,21 @@ m_getfld (m_getfld_state_t *gstate, char name[NAMESZ], char *buf, int *bufsz, n = 0; for (finished = 0; ! finished; ) { while (c != '\n' && c != EOF && n++ < max) { - *cp++ = c = Getc (s); + if ((c = Getc (s)) != EOF) { *cp++ = c; } } if (c != EOF) c = Peek (s); if (max < n) { - /* the dest buffer is full */ + /* The dest buffer is full. Need to back the read + pointer up by one because when m_getfld() is + reentered, it will read a character. Then + we'll jump right to the FLDPLUS handling code, + which will not store that character, but + instead move on to the next one. */ + if (s->readpos > s->msg_buf) { + --s->readpos; + --s->bytes_read; + } s->state = FLDPLUS; finished = 1; } else if (c != ' ' && c != '\t') { @@ -787,7 +799,7 @@ m_unknown(m_getfld_state_t *gstate, FILE *iob) s->msg_style = MS_UNKNOWN; for (i = 0, cp = text; i < sizeof text; ++i, ++cp) { - if ((*cp = Getc (s)) == EOF) { + if ((signed char) (*cp = Getc (s)) == EOF) { break; } } @@ -867,7 +879,7 @@ m_Eom (m_getfld_state_t s, int c) char *cp; for (i = 0, cp = text; i < s->edelimlen; ++i, ++cp) { - if ((*cp = Getc (s)) == EOF) { + if ((signed char) (*cp = Getc (s)) == EOF) { break; } }