@@ -2287,27 +2287,26 @@ int freadMain(freadMainArgs _args)
22872287 if (ch [1 ] == '\r' || ch [1 ] == '\n' || ch [1 ] == '\0' ) { ch ++ ; break ; }
22882288 }
22892289 }
2290- const char * lineEnd = ch ;
2291- const char * nextLine = NULL ;
22922290 if (commentChar ) {
22932291 // fast-trim trailing comment text after the header names
2294- const char * commentPos = skip_to_comment_or_nonwhite (lineEnd );
2292+ const char * commentPos = skip_to_comment_or_nonwhite (ch );
22952293 if (commentPos < eof && * commentPos == commentChar ) {
2296- lineEnd = commentPos ;
2297- nextLine = skip_line (commentPos , eof );
2294+ ch = skip_line (commentPos , eof );
22982295 }
22992296 }
2300- if (nextLine ) {
2301- pos = nextLine ;
2302- } else if (lineEnd == eof || * lineEnd == '\0' ) {
2303- pos = lineEnd ;
2304- } else {
2305- const char * tmp = lineEnd ;
2306- if (eol (& tmp )) {
2307- pos = (tmp < eof ) ? tmp + 1 : tmp ;
2297+ if (ch == eof || * ch == '\0' ) {
2298+ pos = ch ;
2299+ } else if (* ch == '\n' || * ch == '\r' ) {
2300+ if (eol (& ch )) {
2301+ if (ch < eof ) ch ++ ;
2302+ pos = ch ;
23082303 } else {
2309- INTERNAL_STOP ("reading colnames ending on '%c'" , * lineEnd ); // # nocov
2304+ INTERNAL_STOP ("reading colnames ending on '%c'" , * ch ); // # nocov
23102305 }
2306+ } else if (ch > sof && (ch [-1 ] == '\n' || ch [-1 ] == '\r' )) {
2307+ pos = ch ;
2308+ } else {
2309+ INTERNAL_STOP ("reading colnames ending on '%c'" , * ch ); // # nocov
23112310 }
23122311 // now on first data row (row after column names)
23132312 // when fill=TRUE and column names shorter (test 1635.2), leave calloc initialized lenOff.len==0
@@ -2551,7 +2550,10 @@ int freadMain(freadMainArgs _args)
25512550 // treat lines whose first non-space character is the comment marker as empty
25522551 const char * afterWhite = skip_to_comment_or_nonwhite (tLineStart );
25532552 if (afterWhite < eof && * afterWhite == commentChar ) {
2554- tch = skip_line (afterWhite , eof );
2553+ const char * skip = afterWhite ;
2554+ while (skip < eof && * skip != '\n' && * skip != '\r' ) skip ++ ;
2555+ if (skip < eof && eol (& skip )) skip ++ ;
2556+ tch = skip ;
25552557 continue ;
25562558 }
25572559 }
@@ -2702,7 +2704,8 @@ int freadMain(freadMainArgs _args)
27022704 if (commentChar ) {
27032705 const char * commentPtr = skip_to_comment_or_nonwhite (tch );
27042706 if (commentPtr < eof && * commentPtr == commentChar ) {
2705- tch = skip_line (commentPtr , eof );
2707+ tch = commentPtr ;
2708+ while (tch < eof && * tch != '\n' && * tch != '\r' ) tch ++ ;
27062709 break ;
27072710 }
27082711 }
0 commit comments