Skip to content

Commit

Permalink
Remove assert (eof_s != cs), use check instead in get_next_pptoken_1.
Browse files Browse the repository at this point in the history
Process null eof_s in processing.  Define null eof_s for emppty
streams.  Add new test for issue353.
  • Loading branch information
vnmakarov committed Jan 17, 2024
1 parent d62b209 commit 55ec6a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions c-tests/new/issue353-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define i
1 change: 1 addition & 0 deletions c-tests/new/issue353-2.c.expectrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
7 changes: 3 additions & 4 deletions c2mir/c2mir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,13 +1525,12 @@ static token_t get_next_pptoken_1 (c2m_ctx_t c2m_ctx, int header_p) {
case EOF: {
pos_t pos = cs->pos;

assert (eof_s != cs);
if (eof_s != NULL) free_stream (eof_s);
if (cs->f != stdin && cs->f != NULL) {
if (eof_s != cs && cs->f != stdin && cs->f != NULL) {
fclose (cs->f);
cs->f = NULL;
}
eof_s = VARR_POP (stream_t, streams);
eof_s = VARR_LENGTH (stream_t, streams) == 0 ? NULL : VARR_POP (stream_t, streams);
if (VARR_LENGTH (stream_t, streams) == 0) {
return new_token (c2m_ctx, pos, "<EOU>", T_EOU, N_IGNORE);
}
Expand Down Expand Up @@ -3577,7 +3576,7 @@ static void processing (c2m_ctx_t c2m_ctx, int ignore_directive_p) {
out_token (c2m_ctx, t);
continue;
} else if (t->code == T_EOFILE || t->code == T_EOU) {
if (VARR_LENGTH (ifstate_t, ifs) > eof_s->ifs_length_at_stream_start) {
if (VARR_LENGTH (ifstate_t, ifs) > (eof_s == NULL ? 0 : eof_s->ifs_length_at_stream_start)) {
error (c2m_ctx, VARR_LAST (ifstate_t, ifs)->if_pos, "unfinished #if");
}
if (t->code == T_EOU) return;
Expand Down

0 comments on commit 55ec6a7

Please sign in to comment.