diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-06-14 10:41:40 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-06-14 10:41:40 +0200 |
| commit | 6c4fef24e2ccd1a583e7d4ce4e07b4097512e860 (patch) | |
| tree | 4e9597f6f762d48c2c043a9971b2196e62c33ab5 | |
| parent | 3ef857c28f55a0318e22fb1fb01da9c866156f76 (diff) | |
| download | libcsv-6c4fef24e2ccd1a583e7d4ce4e07b4097512e860.tar.gz libcsv-6c4fef24e2ccd1a583e7d4ce4e07b4097512e860.tar.bz2 libcsv-6c4fef24e2ccd1a583e7d4ce4e07b4097512e860.zip | |
benutze Speicherallokierungen getrennten Argumenten für Größe und Anzahl der Elemente
| -rw-r--r-- | csv-test.c | 4 |
1 files changed, 2 insertions, 2 deletions
| @@ -70,7 +70,7 @@ csv_field_init(csv_field_t *csv_field) | |||
| 70 | { | 70 | { |
| 71 | static const size_t INITIAL_CAP = 16; | 71 | static const size_t INITIAL_CAP = 16; |
| 72 | 72 | ||
| 73 | if ( (csv_field->fields = malloc(INITIAL_CAP * sizeof(csv_field->fields[0]))) != NULL ) { | 73 | if ( (csv_field->fields = calloc(INITIAL_CAP, sizeof(csv_field->fields[0]))) != NULL ) { |
| 74 | csv_field->cap = INITIAL_CAP; | 74 | csv_field->cap = INITIAL_CAP; |
| 75 | csv_field->pos = 0; | 75 | csv_field->pos = 0; |
| 76 | } | 76 | } |
| @@ -87,7 +87,7 @@ csv_field_append(csv_field_t *csv_field, int idx) | |||
| 87 | { | 87 | { |
| 88 | if ( csv_field->pos == csv_field->cap ) { /* grow if needed */ | 88 | if ( csv_field->pos == csv_field->cap ) { /* grow if needed */ |
| 89 | int cap = (csv_field->cap * 3) / 2; /* *= 1.5 */ | 89 | int cap = (csv_field->cap * 3) / 2; /* *= 1.5 */ |
| 90 | int *fields = realloc(csv_field->fields, cap * sizeof(csv_field->fields[0])); | 90 | int *fields = reallocarray(csv_field->fields, cap, sizeof(csv_field->fields[0])); |
| 91 | if ( fields == NULL ) { | 91 | if ( fields == NULL ) { |
| 92 | return; | 92 | return; |
| 93 | } | 93 | } |
