diff options
| author | David M. Syzdek <david@syzdek.net> | 2019-11-30 02:55:54 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2019-11-30 02:55:54 -0900 |
| commit | 6a5729be6747957665fff897309e3056c4a04602 (patch) | |
| tree | e5de4ed433cc58676860a6338f0871d3afe3480e /src | |
| parent | 0a57c8821db4e0cd4036a6aaba0d68b1038801bb (diff) | |
| download | ldap-utils-6a5729be6747957665fff897309e3056c4a04602.tar.gz ldap-utils-6a5729be6747957665fff897309e3056c4a04602.tar.bz2 ldap-utils-6a5729be6747957665fff897309e3056c4a04602.tar.xz ldap-utils-6a5729be6747957665fff897309e3056c4a04602.zip | |
ldap2csv: refactoring array initialization
Diffstat (limited to 'src')
| -rw-r--r-- | src/ldap2csv.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/ldap2csv.c b/src/ldap2csv.c index 6cfd27d..1308b07 100644 --- a/src/ldap2csv.c +++ b/src/ldap2csv.c | |||
| @@ -205,7 +205,7 @@ int main(int argc, char * argv[]) | |||
| 205 | 205 | ||
| 206 | // prints attribute names | 206 | // prints attribute names |
| 207 | printf("\"%s\"", cnf->titles[0]); | 207 | printf("\"%s\"", cnf->titles[0]); |
| 208 | for(x = 1; cnf->titles[x]; x++) | 208 | for(x = 1; ((cnf->titles[x])); x++) |
| 209 | printf(",\"%s\"", cnf->titles[x]); | 209 | printf(",\"%s\"", cnf->titles[x]); |
| 210 | printf("\n"); | 210 | printf("\n"); |
| 211 | 211 | ||
| @@ -234,6 +234,8 @@ int my_config(int argc, char * argv[], MyConfig ** cnfp) | |||
| 234 | int option_index; | 234 | int option_index; |
| 235 | char * str; | 235 | char * str; |
| 236 | MyConfig * cnf; | 236 | MyConfig * cnf; |
| 237 | size_t len; | ||
| 238 | size_t size; | ||
| 237 | 239 | ||
| 238 | static char short_options[] = MY_SHORT_OPTIONS; | 240 | static char short_options[] = MY_SHORT_OPTIONS; |
| 239 | static struct option long_options[] = | 241 | static struct option long_options[] = |
| @@ -327,24 +329,29 @@ int my_config(int argc, char * argv[], MyConfig ** cnfp) | |||
| 327 | }; | 329 | }; |
| 328 | 330 | ||
| 329 | // configures LDAP attributes to return in results | 331 | // configures LDAP attributes to return in results |
| 330 | if (!(cnf->lud->attrs = (char **) malloc(sizeof(char *) * (size_t)(argc-optind+1)))) | 332 | len = (size_t)(argc - optind) + 1; |
| 333 | size = sizeof(char *) * len; | ||
| 334 | if (!(cnf->lud->attrs = (char **) malloc(size))) | ||
| 331 | { | 335 | { |
| 332 | fprintf(stderr, "%s: out of virtual memory\n", cnf->prog_name); | 336 | fprintf(stderr, "%s: out of virtual memory\n", cnf->prog_name); |
| 333 | my_unbind(cnf); | 337 | my_unbind(cnf); |
| 334 | return(1); | 338 | return(1); |
| 335 | }; | 339 | }; |
| 336 | if (!(cnf->defvals = (const char **) malloc(sizeof(char *) * (size_t)(argc-optind+1)))) | 340 | bzero(cnf->lud->attrs, size); |
| 341 | if (!(cnf->defvals = (const char **) malloc(size))) | ||
| 337 | { | 342 | { |
| 338 | fprintf(stderr, "%s: out of virtual memory\n", cnf->prog_name); | 343 | fprintf(stderr, "%s: out of virtual memory\n", cnf->prog_name); |
| 339 | my_unbind(cnf); | 344 | my_unbind(cnf); |
| 340 | return(1); | 345 | return(1); |
| 341 | }; | 346 | }; |
| 342 | if (!(cnf->titles = (const char **) malloc(sizeof(char *) * (size_t)(argc-optind+1)))) | 347 | bzero(cnf->defvals, size); |
| 348 | if (!(cnf->titles = (const char **) malloc(size))) | ||
| 343 | { | 349 | { |
| 344 | fprintf(stderr, "%s: out of virtual memory\n", cnf->prog_name); | 350 | fprintf(stderr, "%s: out of virtual memory\n", cnf->prog_name); |
| 345 | my_unbind(cnf); | 351 | my_unbind(cnf); |
| 346 | return(1); | 352 | return(1); |
| 347 | }; | 353 | }; |
| 354 | bzero(cnf->titles, size); | ||
| 348 | for(c = 0; c < (argc-optind); c++) | 355 | for(c = 0; c < (argc-optind); c++) |
| 349 | { | 356 | { |
| 350 | cnf->lud->attrs[c] = argv[optind+c]; | 357 | cnf->lud->attrs[c] = argv[optind+c]; |
