mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 02:06:22 +00:00
refactor: Refactor form_set_value to use glib list management
Simplify how field values are updated and ensure memory is correctly managed. The previous implementation relied on manual manipulation of the GSList internal `data` member and only handled cases where a field had zero or one existing value. The function now correctly handles fields that may already contain multiple values by using 'g_slist_free_full' to clear the entire list and its contents before setting the new value.
This commit is contained in:
@@ -477,16 +477,13 @@ form_set_value(DataForm* form, const char* const tag, char* value)
|
|||||||
while (curr) {
|
while (curr) {
|
||||||
FormField* field = curr->data;
|
FormField* field = curr->data;
|
||||||
if (g_strcmp0(field->var, var) == 0) {
|
if (g_strcmp0(field->var, var) == 0) {
|
||||||
if (g_slist_length(field->values) == 0) {
|
if (field->values) {
|
||||||
field->values = g_slist_append(field->values, strdup(value));
|
g_slist_free_full(field->values, free);
|
||||||
form->modified = TRUE;
|
field->values = NULL;
|
||||||
return;
|
|
||||||
} else if (g_slist_length(field->values) == 1) {
|
|
||||||
free(field->values->data);
|
|
||||||
field->values->data = strdup(value);
|
|
||||||
form->modified = TRUE;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
field->values = g_slist_append(NULL, strdup(value));
|
||||||
|
form->modified = TRUE;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
curr = g_slist_next(curr);
|
curr = g_slist_next(curr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user