X-Git-Url: https://deadsoftware.ru/gitweb?p=flatwaifu.git;a=blobdiff_plain;f=src%2Fconfig.c;h=1980bc61ec2986f13e9d82bfe4100a47abecfa9e;hp=80c94bf3c85613e268342fc1eba88e42075ab582;hb=4a99fe51561ca331df54512eb25c502d0fcd2b55;hpb=efb17348438f10c929e2e9807013969f71802661 diff --git a/src/config.c b/src/config.c index 80c94bf..1980bc6 100644 --- a/src/config.c +++ b/src/config.c @@ -35,15 +35,20 @@ static int ch; const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) { assert(key != NULL); - assert(cfg != NULL); - int i = 0; - while (cfg[i].cfg && strcasecmp(cfg[i].cfg, key) != 0) { - i++; + if (cfg != NULL) { + int i = 0; + while (cfg[i].cfg && strcasecmp(cfg[i].cfg, key) != 0) { + i++; + } + return cfg[i].cfg ? &cfg[i] : NULL; + } else { + return NULL; } - return cfg[i].cfg ? &cfg[i] : NULL; } int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) { + assert(key != NULL); + assert(value != NULL); const cfg_t *entry = CFG_find_entry(key, cfg); if (entry != NULL) { void *p = entry->p; @@ -58,6 +63,7 @@ int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) { case Y_KEY: *(int*)p = I_string_to_key(value); break; default: assert(0); // unknown type -> something broken } + //logo("CFG_update_key: [%s] = [%s]\n", key, value); return 1; } else { return 0; @@ -244,9 +250,11 @@ int CFG_update_config (const char *old, const char *new, int n, const cfg_t **cf CFG_close_iterator(); } for (j = 0; j < n; j++) { - i = 0; - while (CFG_write_entry(nf, &cfg[j][i])) { - i++; + if (cfg[j] != NULL) { + i = 0; + while (CFG_write_entry(nf, &cfg[j][i])) { + i++; + } } } fclose(nf);