forked from osmocom/wireshark
wiretap: fix return value of wtap_register_file_type_subtypes().
It was returning the length of the array *after* we added the new entry, which is the index that would be used for the *next* entry added. Return, instead, the length of the array *before* we add the new entry.
This commit is contained in:
parent
43ffb5436c
commit
a931d73e64
|
@ -1359,6 +1359,7 @@ int
|
||||||
wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi)
|
wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi)
|
||||||
{
|
{
|
||||||
struct file_type_subtype_info* finfo;
|
struct file_type_subtype_info* finfo;
|
||||||
|
guint file_type_subtype;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for required fields (description and name).
|
* Check for required fields (description and name).
|
||||||
|
@ -1387,38 +1388,39 @@ wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi)
|
||||||
* (and because entry 0, for WTAP_FILE_TYPE_SUBTYPE_UNKNOWN,
|
* (and because entry 0, for WTAP_FILE_TYPE_SUBTYPE_UNKNOWN,
|
||||||
* has a null name pointer).
|
* has a null name pointer).
|
||||||
*/
|
*/
|
||||||
for (guint i = wtap_num_builtin_file_types_subtypes;
|
for (file_type_subtype = wtap_num_builtin_file_types_subtypes;
|
||||||
i < file_type_subtype_table_arr->len; i++) {
|
file_type_subtype < file_type_subtype_table_arr->len;
|
||||||
if (file_type_subtype_table[i].name == NULL) {
|
file_type_subtype++) {
|
||||||
|
if (file_type_subtype_table[file_type_subtype].name == NULL) {
|
||||||
/*
|
/*
|
||||||
* We found such an entry.
|
* We found such an entry.
|
||||||
*
|
*
|
||||||
* Get the pointer from the GArray, so that we get a
|
* Get the pointer from the GArray, so that we get a
|
||||||
* non-const pointer.
|
* non-const pointer.
|
||||||
*/
|
*/
|
||||||
finfo = &g_array_index(file_type_subtype_table_arr, struct file_type_subtype_info, i);
|
finfo = &g_array_index(file_type_subtype_table_arr, struct file_type_subtype_info, file_type_subtype);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fill in the entry with the new values.
|
* Fill in the entry with the new values.
|
||||||
*/
|
*/
|
||||||
*finfo = *fi;
|
*finfo = *fi;
|
||||||
|
|
||||||
return (gint)i;
|
return (gint)file_type_subtype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There aren't any free slots, so add a new entry.
|
* There aren't any free slots, so add a new entry.
|
||||||
* Append this entry to the end of the array, change
|
* Get the number of current number of entries, which will
|
||||||
* file_type_subtype_table in case the array had to get reallocated,
|
* be the index of the new entry, then append this entry
|
||||||
* increment the number of entries (XXX - just use the array
|
* to the end of the array, change file_type_subtype_table
|
||||||
* length!), and return subtype, which is now set to the
|
* in case the array had to get reallocated, and return
|
||||||
* old number of entries, which is now the index of the new
|
* the index of the new entry.
|
||||||
* entry.
|
|
||||||
*/
|
*/
|
||||||
g_array_append_val(file_type_subtype_table_arr,*fi);
|
file_type_subtype = file_type_subtype_table_arr->len;
|
||||||
|
g_array_append_val(file_type_subtype_table_arr, *fi);
|
||||||
file_type_subtype_table = (const struct file_type_subtype_info*)(void *)file_type_subtype_table_arr->data;
|
file_type_subtype_table = (const struct file_type_subtype_info*)(void *)file_type_subtype_table_arr->data;
|
||||||
return file_type_subtype_table_arr->len;
|
return file_type_subtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* De-registers a file writer - they can never be removed from the GArray, but we can "clear" an entry.
|
/* De-registers a file writer - they can never be removed from the GArray, but we can "clear" an entry.
|
||||||
|
|
Loading…
Reference in New Issue