if (decoding_fgets(tok->inp,
(int)(tok->end - tok->inp),
tok) == NULL) {
+ /* Break out early on decoding
+ errors, as tok->buf will be NULL
+ */
+ if (tok->decoding_erred)
+ return EOF;
/* Last line does not end in \n,
fake one */
strcpy(tok->inp, "\n");
tok->inp = strchr(tok->inp, '\0');
done = tok->inp[-1] == '\n';
}
- tok->cur = tok->buf + cur;
- /* replace "\r\n" with "\n" */
- /* For Mac we leave the \r, giving a syntax error */
- pt = tok->inp - 2;
- if (pt >= tok->buf && *pt == '\r') {
- *pt++ = '\n';
- *pt = '\0';
- tok->inp = pt;
+ if (tok->buf != NULL) {
+ tok->cur = tok->buf + cur;
+ /* replace "\r\n" with "\n" */
+ /* For Mac we leave the \r, giving a syntax error */
+ pt = tok->inp - 2;
+ if (pt >= tok->buf && *pt == '\r') {
+ *pt++ = '\n';
+ *pt = '\0';
+ tok->inp = pt;
+ }
}
}
if (tok->done != E_OK) {