Skip to content

Commit

Permalink
db_text: fix issues when database file is missing an ending newline
Browse files Browse the repository at this point in the history
* do not crash if file contains columns only and is missing the ending newline
* do not skip the last row of a database file if it lacks an ending newline

Reported by gergelypeli on GitHub
Closes issue #308
(cherry picked from commit a2172b2)
  • Loading branch information
liviuchircu committed Aug 26, 2014
1 parent 9827ee5 commit a50060f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/db_text/dbt_file.c
Expand Up @@ -265,6 +265,14 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
colp0 = colp;
dtp->nrcols++;
c = fgetc(fin);

/* at least 1 column was found. eat all trailing spaces */
while (c == DBT_DELIM_C)
c = fgetc(fin);

/* properly load files which do not end in a newline */
if (c == EOF)
c = DBT_DELIM_R;
}
else
goto clean;
Expand Down Expand Up @@ -468,6 +476,11 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
default:
goto clean;
}

/* do not skip last row if it does not end with a newline */
if (c == EOF)
c = DBT_DELIM_R;

if(c==DBT_DELIM)
c = fgetc(fin);
ccol++;
Expand Down

0 comments on commit a50060f

Please sign in to comment.