# HG changeset patch # User Matti Hamalainen # Date 1578258089 -7200 # Node ID 39a03560163d228651614b509cf08768a32aa7eb # Parent 4a3e8960b3a90c493eeb962316d5a32997bf1f5b Improve STIL parsing reliability. diff -r 4a3e8960b3a9 -r 39a03560163d sidlib.c --- a/sidlib.c Sun Jan 05 22:11:48 2020 +0200 +++ b/sidlib.c Sun Jan 05 23:01:29 2020 +0200 @@ -802,18 +802,6 @@ // Get next character switch (ctx.ch = thfgetc(fh)) { - case EOF: - if (ctx.parseMode != PM_IDLE) - { - ret = th_io_error(fh, THERR_OUT_OF_DATA, - "Unexpected end of file on line #%d", - fh->line); - ctx.parseMode = PM_ERROR; - } - else - ctx.parseMode = PM_EOF; - break; - case '\n': fh->line++; ctx.linePos = -1; @@ -845,6 +833,11 @@ case PM_NEXT: case PM_IDLE: // Normal parsing mode + if (ctx.ch == EOF) + { + sidlib_stildb_set_parsemode(&ctx, PM_EOF); + } + else if (ctx.ch == '#') { sidlib_stildb_set_parsemode(&ctx, PM_COMMENT); @@ -893,7 +886,7 @@ break; case PM_ENTRY: - if (th_iscrlf(ctx.ch) || th_isspace(ctx.ch)) + if (ctx.ch == EOF || th_iscrlf(ctx.ch) || th_isspace(ctx.ch)) { // A new file / entry, allocate and append tmpStr[strPos] = 0; @@ -923,7 +916,7 @@ break; case PM_SUBTUNE: - if (ctx.ch == ')') + if (ctx.ch == EOF || ctx.ch == ')') { BOOL neg = FALSE; @@ -979,7 +972,7 @@ break; case PM_FIELD_NAME: - if (ctx.ch == ':' || th_iscrlf(ctx.ch) || th_isspace(ctx.ch)) + if (ctx.ch == EOF || ctx.ch == ':' || th_iscrlf(ctx.ch) || th_isspace(ctx.ch)) { tmpStr[strPos] = 0; th_pstr_cpy(&fieldName, tmpStr); @@ -1025,7 +1018,7 @@ ctx.ch = -1; } else - if (ctx.lineStart && ctx.linePos < 8) + if (ctx.ch == EOF || (ctx.lineStart && ctx.linePos < 8)) { // Field done tmpStr[strPos] = 0; @@ -1069,6 +1062,7 @@ } out: + th_free(tmpStr); th_free(fieldName);