turns out that set_param with null should remove the setting.

This commit is contained in:
Enno Rehling 2015-01-04 16:41:59 +01:00
parent eb5c912805
commit 04bbec2b89
2 changed files with 11 additions and 2 deletions

View File

@ -1122,8 +1122,15 @@ void set_param(struct param **p, const char *key, const char *data)
while (*p != NULL) {
int cmp = strcmp((*p)->name, key);
if (cmp == 0) {
free((*p)->data);
(*p)->data = _strdup(data);
par = *p;
free(par->data);
if (data) {
par->data = _strdup(data);
}
else {
*p = par->next;
free(par);
}
return;
}
else if (cmp > 0) {

View File

@ -71,6 +71,8 @@ static void test_get_set_param(CuTest * tc)
set_param(&par, "bar", "foo");
CuAssertStrEquals(tc, "bar", get_param(par, "foo"));
CuAssertStrEquals(tc, "foo", get_param(par, "bar"));
set_param(&par, "bar", NULL);
CuAssertPtrEquals(tc, NULL, (void *)get_param(par, "bar"));
}
static void test_param_int(CuTest * tc)