From 0ba2797fdf4577588bcf7f5cac9d94ae43b8b31b Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Fri, 24 Jul 2020 12:23:33 +0200 Subject: Benutze size_t statt int bei Größenangaben MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csv.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'csv.c') diff --git a/csv.c b/csv.c index 3804095..ce8cb00 100644 --- a/csv.c +++ b/csv.c @@ -134,7 +134,7 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const assert(csv_string != NULL); assert(csv_options != NULL); - static const int INITIAL_CAP = 16; + static const size_t INITIAL_CAP = 16; if ( csv_string->pos == csv_string->cap ) { // grow if needed if ( csv_string->str == NULL ) { // first call? @@ -144,9 +144,9 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t *const } csv_string->cap = INITIAL_CAP; } - else { // subsequent call - int cap = (csv_string->cap * 3) / 2; // *= 1.5 - char *str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); + else { // subsequent call + size_t cap = (csv_string->cap * 3) / 2; // *= 1.5 + char * str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); if ( str == NULL ) { csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); return; @@ -192,7 +192,7 @@ csv_field_reset(csv_field_t *csv_field) } static inline void -csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t *const csv_options) +csv_field_append(csv_field_t *csv_field, size_t idx, const csv_options_t *const csv_options) { assert(csv_field != NULL); assert(csv_options != NULL); @@ -207,9 +207,9 @@ csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t *const csv } csv_field->cap = INITIAL_CAP; } - else { // subsequent call - int cap = (csv_field->cap * 3) / 2; // *= 1.5 - int *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg); + else { // subsequent call + size_t cap = (csv_field->cap * 3) / 2; // *= 1.5 + size_t *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg); if ( fields == NULL ) { csv_fatal_error(CSV_ERR_OUT_OF_MEMORY, csv_options); return; @@ -270,7 +270,7 @@ csv_cleanup(csv_t *csv) csv->csv_options = NULL; } -int +size_t csv_nfields(const csv_t *const csv) { assert(csv != NULL); @@ -279,7 +279,7 @@ csv_nfields(const csv_t *const csv) } const char * -csv_field(const csv_t *const csv, int idx) +csv_field(const csv_t *const csv, size_t idx) { assert(csv != NULL); assert(idx >= 0 && idx < csv->csv_field.pos); @@ -304,13 +304,13 @@ csv_read(csv_t *csv, FILE *in) if ( ferror(in) ) { csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); - return EOF; + return 0; } // do not try to read if EOF has already been seen if ( feof(in) ) { csv_cleanup(csv); - return EOF; + return 0; } enum { @@ -442,12 +442,12 @@ csv_read(csv_t *csv, FILE *in) case STATE_END_FILE: if ( ferror(in) ) { csv_fatal_error(CSV_ERR_IO_READ, csv->csv_options); - return EOF; + return 0; } if ( csv_string_empty(&csv->csv_string) ) { csv_cleanup(csv); - return EOF; // EOF reached + return 0; // EOF reached } /* -- cgit v1.3