# HG changeset patch # User Matti Hamalainen # Date 1188952110 -10800 # Node ID 7d1dee4f660a1b61d2de0763494b77a938b22202 # Parent 62b78f2aa4507e1a861e159cdf910de554261109 Check for known fields in tuple_associate_data() when given nfield is undefined. diff -r 62b78f2aa450 -r 7d1dee4f660a src/audacious/tuple.c --- a/src/audacious/tuple.c Tue Sep 04 22:11:22 2007 +0300 +++ b/src/audacious/tuple.c Wed Sep 05 03:28:30 2007 +0300 @@ -132,16 +132,22 @@ static gboolean -tuple_associate_data(const gchar **tfield, TupleValue **value, Tuple *tuple, const gint nfield, const gchar *field) +tuple_associate_data(const gchar **tfield, TupleValue **value, Tuple *tuple, gint *nfield, const gchar *field) { g_return_val_if_fail(tuple != NULL, FALSE); - g_return_val_if_fail(nfield < FIELD_LAST, FALSE); + g_return_val_if_fail(*nfield < FIELD_LAST, FALSE); - if (nfield < 0) + /* Check for known fields */ + if (*nfield < 0) { + gint i; *tfield = field; - else { - *tfield = tuple_fields[nfield]; - tuple->values[nfield] = NULL; + for (i = 0; i < FIELD_LAST && *nfield < 0; i++) + if (!strcmp(field, tuple_fields[i])) *nfield = i; + } + + if (*nfield >= 0) { + *tfield = tuple_fields[*nfield]; + tuple->values[*nfield] = NULL; } if ((*value = mowgli_dictionary_delete(tuple->dict, *tfield))) @@ -164,8 +170,9 @@ { TupleValue *value; const gchar *tfield; + gint ifield = nfield; - if (!tuple_associate_data(&tfield, &value, tuple, nfield, field)) + if (!tuple_associate_data(&tfield, &value, tuple, &ifield, field)) return FALSE; if (string == NULL) @@ -175,7 +182,7 @@ value->type = TUPLE_STRING; value->value.string = g_strdup(string); - tuple_associate_data2(tuple, nfield, tfield, value); + tuple_associate_data2(tuple, ifield, tfield, value); return TRUE; } @@ -184,15 +191,16 @@ { TupleValue *value; const gchar *tfield; + gint ifield = nfield; - if (!tuple_associate_data(&tfield, &value, tuple, nfield, field)) + if (!tuple_associate_data(&tfield, &value, tuple, &ifield, field)) return FALSE; value = mowgli_heap_alloc(tuple_value_heap); value->type = TUPLE_INT; value->value.integer = integer; - tuple_associate_data2(tuple, nfield, tfield, value); + tuple_associate_data2(tuple, ifield, tfield, value); return TRUE; }