diff options
| -rw-r--r-- | csv.c | 20 |
1 files changed, 10 insertions, 10 deletions
| @@ -48,7 +48,7 @@ csv_mem_allocate(size_t n, size_t sz, void *cb_arg) | |||
| 48 | { | 48 | { |
| 49 | UNUSED(cb_arg); | 49 | UNUSED(cb_arg); |
| 50 | 50 | ||
| 51 | size_t len; | 51 | size_t len = 0; |
| 52 | if ( n == 0 || sz == 0 || mul_overflow(n, sz, &len) ) { | 52 | if ( n == 0 || sz == 0 || mul_overflow(n, sz, &len) ) { |
| 53 | return NULL; | 53 | return NULL; |
| 54 | } | 54 | } |
| @@ -60,7 +60,7 @@ csv_mem_reallocate(void *ptr, size_t n, size_t sz, void *cb_arg) | |||
| 60 | { | 60 | { |
| 61 | UNUSED(cb_arg); | 61 | UNUSED(cb_arg); |
| 62 | 62 | ||
| 63 | size_t len; | 63 | size_t len = 0; |
| 64 | if ( n == 0 || sz == 0 || mul_overflow(n, sz, &len) ) { | 64 | if ( n == 0 || sz == 0 || mul_overflow(n, sz, &len) ) { |
| 65 | return NULL; | 65 | return NULL; |
| 66 | } | 66 | } |
| @@ -96,7 +96,7 @@ csv_fatal_error(csv_err_t csv_err, const csv_options_t *const csv_options) | |||
| 96 | if ( csv_options->cb_error != NULL ) { | 96 | if ( csv_options->cb_error != NULL ) { |
| 97 | (*csv_options->cb_error)(csv_err, csv_options->cb_error_arg); | 97 | (*csv_options->cb_error)(csv_err, csv_options->cb_error_arg); |
| 98 | } | 98 | } |
| 99 | fprintf(stderr, "fatal error: %s\n", csv_err_str(csv_err)); | 99 | (void) fprintf(stderr, "fatal error: %s\n", csv_err_str(csv_err)); |
| 100 | abort(); | 100 | abort(); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| @@ -129,7 +129,7 @@ csv_string_isempty(csv_string_t *csv_string) | |||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | static inline void | 131 | static inline void |
| 132 | csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const csv_options) | 132 | csv_string_append(csv_string_t *csv_string, int ch, const csv_options_t *const csv_options) |
| 133 | { | 133 | { |
| 134 | assert(csv_string != NULL); | 134 | assert(csv_string != NULL); |
| 135 | assert(csv_options != NULL); | 135 | assert(csv_options != NULL); |
| @@ -146,7 +146,7 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const | |||
| 146 | } | 146 | } |
| 147 | else { // subsequent call | 147 | else { // subsequent call |
| 148 | size_t cap = (csv_string->cap * 3) / 2; // *= 1.5 | 148 | size_t cap = (csv_string->cap * 3) / 2; // *= 1.5 |
| 149 | char * str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); | 149 | char *str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); |
| 150 | if ( str == NULL ) { | 150 | if ( str == NULL ) { |
| 151 | csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); | 151 | csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); |
| 152 | return; | 152 | return; |
| @@ -156,7 +156,7 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const | |||
| 156 | } | 156 | } |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | csv_string->str[csv_string->pos++] = ch; // append char | 159 | csv_string->str[csv_string->pos++] = (char) ch; // append char |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | static inline void | 162 | static inline void |
| @@ -341,7 +341,7 @@ csv_read(csv_t *csv, FILE *in) | |||
| 341 | else if ( ch == '\r' ) { // test for CR.. | 341 | else if ( ch == '\r' ) { // test for CR.. |
| 342 | ch = getc(in); | 342 | ch = getc(in); |
| 343 | if ( ch != '\n' ) { // ..LF | 343 | if ( ch != '\n' ) { // ..LF |
| 344 | ungetc(ch, in); | 344 | (void) ungetc(ch, in); |
| 345 | } | 345 | } |
| 346 | state = STATE_END_LINE; | 346 | state = STATE_END_LINE; |
| 347 | } | 347 | } |
| @@ -382,7 +382,7 @@ csv_read(csv_t *csv, FILE *in) | |||
| 382 | else if ( ch == '\r' ) { | 382 | else if ( ch == '\r' ) { |
| 383 | ch = getc(in); | 383 | ch = getc(in); |
| 384 | if ( ch != '\n' ) { | 384 | if ( ch != '\n' ) { |
| 385 | ungetc(ch, in); | 385 | (void) ungetc(ch, in); |
| 386 | } | 386 | } |
| 387 | state = STATE_END_LINE; | 387 | state = STATE_END_LINE; |
| 388 | } | 388 | } |
| @@ -391,7 +391,7 @@ csv_read(csv_t *csv, FILE *in) | |||
| 391 | } | 391 | } |
| 392 | else { | 392 | else { |
| 393 | csv_string_append(&csv->csv_string, DELIM, csv->csv_options); | 393 | csv_string_append(&csv->csv_string, DELIM, csv->csv_options); |
| 394 | ungetc(ch, in); // we have read too far... Put the character back! | 394 | (void) ungetc(ch, in); // we have read too far... Put the character back! |
| 395 | } | 395 | } |
| 396 | } | 396 | } |
| 397 | else { | 397 | else { |
| @@ -414,7 +414,7 @@ csv_read(csv_t *csv, FILE *in) | |||
| 414 | else if ( ch == '\r' ) { | 414 | else if ( ch == '\r' ) { |
| 415 | ch = getc(in); | 415 | ch = getc(in); |
| 416 | if ( ch != '\n' ) { | 416 | if ( ch != '\n' ) { |
| 417 | ungetc(ch, in); | 417 | (void) ungetc(ch, in); |
| 418 | } | 418 | } |
| 419 | state = STATE_END_LINE; | 419 | state = STATE_END_LINE; |
| 420 | } | 420 | } |
