Skip to content

Commit d715317

Browse files
author
Dan Brown
committed
fix 2 difficult bugs: prefer memchr instead of strchr when working with unsigned char, and handle case when opening quote is at end of chunk
1 parent 27cc623 commit d715317

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

csvquote.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ const unsigned char del, const unsigned char quo, const unsigned char rec) {
3838
stopat = buffer + (nbytes);
3939
// scan for quote characters in the chunk
4040
while (c < stopat) {
41-
q_next = (unsigned char *) strchr((char *)c, quo);
41+
q_next = (unsigned char *) memchr(c, quo, stopat - c);
4242
if (q_start == NULL) { // unquoted state
4343
if (q_next == NULL) { // opening quote not yet found
44-
c = stopat; // done with this chunk
44+
//c = stopat; // done with this chunk
45+
break;
4546
} else { // opening quote found
4647
q_start = q_next;
4748
c = q_start + 1;
49+
if (c == stopat) {
50+
q_start = buffer - 1;
51+
break;
52+
}
4853
}
4954
} else { // quoted state
5055
c = q_start + 1; // starting pointer for translation

0 commit comments

Comments
 (0)