diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-06-14 17:26:06 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-06-14 17:26:06 +0200 |
| commit | dacba96a56a325d6aa431c64553dd34d5d99b642 (patch) | |
| tree | 0fb39d2d48f2a34c7ec1d5fc7ec4e5f67164934b /csv-test.c | |
| parent | d0a8e4d7c49f3d082981318f37181da2d10d7886 (diff) | |
| download | libcsv-dacba96a56a325d6aa431c64553dd34d5d99b642.tar.gz libcsv-dacba96a56a325d6aa431c64553dd34d5d99b642.tar.bz2 libcsv-dacba96a56a325d6aa431c64553dd34d5d99b642.zip | |
mehr Fehlerprüfungen
Diffstat (limited to 'csv-test.c')
| -rw-r--r-- | csv-test.c | 22 |
1 files changed, 17 insertions, 5 deletions
| @@ -188,6 +188,7 @@ int | |||
| 188 | csv_init_opt(csv_t *csv, FILE *in, csv_options_t *csv_options) | 188 | csv_init_opt(csv_t *csv, FILE *in, csv_options_t *csv_options) |
| 189 | { | 189 | { |
| 190 | assert(csv != NULL); | 190 | assert(csv != NULL); |
| 191 | assert(in != NULL); | ||
| 191 | 192 | ||
| 192 | csv->in = in; | 193 | csv->in = in; |
| 193 | csv->csv_options = ( csv_options != NULL ) ? csv_options : &default_csv_options; | 194 | csv->csv_options = ( csv_options != NULL ) ? csv_options : &default_csv_options; |
| @@ -233,8 +234,14 @@ const char * | |||
| 233 | csv_field(csv_t *csv, int idx) | 234 | csv_field(csv_t *csv, int idx) |
| 234 | { | 235 | { |
| 235 | assert(csv != NULL); | 236 | assert(csv != NULL); |
| 237 | assert(idx >= 0 && idx < csv->csv_field.pos); | ||
| 236 | 238 | ||
| 237 | return &csv->csv_string.str[csv->csv_field.fields[idx]]; | 239 | if ( idx >= 0 && idx < csv->csv_field.pos) { |
| 240 | return &csv->csv_string.str[csv->csv_field.fields[idx]]; | ||
| 241 | } | ||
| 242 | else { | ||
| 243 | return NULL; | ||
| 244 | } | ||
| 238 | } | 245 | } |
| 239 | 246 | ||
| 240 | int | 247 | int |
| @@ -373,6 +380,10 @@ csv_read(csv_t *csv) | |||
| 373 | 380 | ||
| 374 | /* ... und die Anzahl der Felder zurückliefern! */ | 381 | /* ... und die Anzahl der Felder zurückliefern! */ |
| 375 | return csv->csv_field.pos; | 382 | return csv->csv_field.pos; |
| 383 | |||
| 384 | default: | ||
| 385 | assert(!"this should never be happen..."); | ||
| 386 | break; | ||
| 376 | } | 387 | } |
| 377 | } | 388 | } |
| 378 | /* NOT REACHED */ | 389 | /* NOT REACHED */ |
| @@ -430,11 +441,12 @@ main(void) | |||
| 430 | 441 | ||
| 431 | clock_t start = clock(); | 442 | clock_t start = clock(); |
| 432 | 443 | ||
| 433 | csv_init(csv, stdin); | 444 | if ( csv_init(csv, stdin) == CSV_OK ) { |
| 434 | while ( (n = csv_read(csv)) != -1 ) { | 445 | while ( (n = csv_read(csv)) != -1 ) { |
| 435 | ++line; | 446 | ++line; |
| 447 | } | ||
| 448 | csv_free(csv); | ||
| 436 | } | 449 | } |
| 437 | csv_free(csv); | ||
| 438 | 450 | ||
| 439 | clock_t end = clock(); | 451 | clock_t end = clock(); |
| 440 | 452 | ||
