forked from osmocom/wireshark
WMEM: Add strjoin routines.
Add wmem versions corresponding to g_strjoin() and g_strjoinv(). Modify packet-rtps.c to use wmem routines_ where it is now using g_ routines causing mallocs. Change-Id: I92c890a8b8f29a973e103676d8e5a681ee5abd50 Reviewed-on: https://code.wireshark.org/review/25764 Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
2cf6517ec0
commit
d1ce1baf63
|
@ -3963,12 +3963,10 @@ static void rtps_util_format_typename(gchar * type_name, gchar ** output) {
|
||||||
gchar * result_caps;
|
gchar * result_caps;
|
||||||
/* The standard specifies that the max size of a type name
|
/* The standard specifies that the max size of a type name
|
||||||
can be 255 bytes */
|
can be 255 bytes */
|
||||||
tokens = g_strsplit(type_name, "::", 255);
|
tokens = wmem_strsplit(wmem_packet_scope(), type_name, "::", 255);
|
||||||
result_caps = g_strjoinv("_", tokens);
|
result_caps = wmem_strjoinv(wmem_packet_scope(), "_", tokens);
|
||||||
*output = g_ascii_strdown(result_caps, -1);
|
*output = wmem_ascii_strdown(wmem_packet_scope(), result_caps, -1);
|
||||||
|
|
||||||
g_strfreev(tokens);
|
|
||||||
g_free(result_caps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtps_util_topic_info_add_tree(proto_tree *tree, tvbuff_t *tvb,
|
static void rtps_util_topic_info_add_tree(proto_tree *tree, tvbuff_t *tvb,
|
||||||
|
@ -4015,18 +4013,12 @@ static gboolean rtps_util_topic_info_add_column_info_and_try_dissector(proto_tre
|
||||||
}
|
}
|
||||||
/* This part tries to dissect the content using a dissector */
|
/* This part tries to dissect the content using a dissector */
|
||||||
next_tvb = tvb_new_subset_remaining(tvb, offset);
|
next_tvb = tvb_new_subset_remaining(tvb, offset);
|
||||||
/* After calling this API, we must call g_free in dissector_name */
|
|
||||||
rtps_util_format_typename(type_mapping_object->type_name, &dissector_name);
|
rtps_util_format_typename(type_mapping_object->type_name, &dissector_name);
|
||||||
if (dissector_try_string(rtps_type_name_table, dissector_name,
|
return dissector_try_string(rtps_type_name_table, dissector_name,
|
||||||
next_tvb, pinfo, tree, data)) {
|
next_tvb, pinfo, tree, data);
|
||||||
g_free(dissector_name);
|
|
||||||
return TRUE;
|
|
||||||
} else {
|
|
||||||
g_free(dissector_name);
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* Return false so the content is dissected by the codepath following this one */
|
/* Return false so the content is dissected by the codepath following this one */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,87 @@ wmem_strconcat(wmem_allocator_t *allocator, const gchar *first, ...)
|
||||||
return concat;
|
return concat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
wmem_strjoin(wmem_allocator_t *allocator,
|
||||||
|
const gchar *separator, const gchar *first, ...)
|
||||||
|
{
|
||||||
|
gsize len;
|
||||||
|
va_list args;
|
||||||
|
gsize separator_len;
|
||||||
|
gchar *s;
|
||||||
|
gchar *concat;
|
||||||
|
gchar *ptr;
|
||||||
|
|
||||||
|
if (!first)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (separator == NULL) {
|
||||||
|
separator = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
separator_len = strlen (separator);
|
||||||
|
|
||||||
|
len = 1 + strlen(first); /* + 1 for null byte */
|
||||||
|
va_start(args, first);
|
||||||
|
while ((s = va_arg(args, gchar*))) {
|
||||||
|
len += (separator_len + strlen(s));
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
ptr = concat = (gchar *)wmem_alloc(allocator, len);
|
||||||
|
ptr = g_stpcpy(ptr, first);
|
||||||
|
va_start(args, first);
|
||||||
|
while ((s = va_arg(args, gchar*))) {
|
||||||
|
ptr = g_stpcpy(ptr, separator);
|
||||||
|
ptr = g_stpcpy(ptr, s);
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return concat;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
wmem_strjoinv(wmem_allocator_t *allocator,
|
||||||
|
const gchar *separator, gchar **str_array)
|
||||||
|
{
|
||||||
|
gchar *string = NULL;
|
||||||
|
|
||||||
|
if (!str_array)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (separator == NULL) {
|
||||||
|
separator = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_array[0]) {
|
||||||
|
gint i;
|
||||||
|
gchar *ptr;
|
||||||
|
gsize len, separator_len;
|
||||||
|
|
||||||
|
separator_len = strlen(separator);
|
||||||
|
|
||||||
|
/* Get first part of length. Plus one for null byte. */
|
||||||
|
len = 1 + strlen(str_array[0]);
|
||||||
|
/* Get the full length, including the separators. */
|
||||||
|
for (i = 1; str_array[i] != NULL; i++) {
|
||||||
|
len += separator_len;
|
||||||
|
len += strlen(str_array[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate and build the string. */
|
||||||
|
string = (gchar *)wmem_alloc(allocator, len);
|
||||||
|
ptr = g_stpcpy(string, str_array[0]);
|
||||||
|
for (i = 1; str_array[i] != NULL; i++) {
|
||||||
|
ptr = g_stpcpy(ptr, separator);
|
||||||
|
ptr = g_stpcpy(ptr, str_array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
gchar **
|
gchar **
|
||||||
wmem_strsplit(wmem_allocator_t *allocator, const gchar *src,
|
wmem_strsplit(wmem_allocator_t *allocator, const gchar *src,
|
||||||
const gchar *delimiter, int max_tokens)
|
const gchar *delimiter, int max_tokens)
|
||||||
|
|
|
@ -54,6 +54,18 @@ gchar *
|
||||||
wmem_strconcat(wmem_allocator_t *allocator, const gchar *first, ...)
|
wmem_strconcat(wmem_allocator_t *allocator, const gchar *first, ...)
|
||||||
G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
|
G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
|
WS_DLL_PUBLIC
|
||||||
|
gchar *
|
||||||
|
wmem_strjoin(wmem_allocator_t *allocator,
|
||||||
|
const gchar *separator, const gchar *first, ...)
|
||||||
|
G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
|
WS_DLL_PUBLIC
|
||||||
|
gchar *
|
||||||
|
wmem_strjoinv(wmem_allocator_t *allocator,
|
||||||
|
const gchar *separator, gchar **str_array)
|
||||||
|
G_GNUC_MALLOC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits a string into a maximum of max_tokens pieces, using the given
|
* Splits a string into a maximum of max_tokens pieces, using the given
|
||||||
* delimiter. If max_tokens is reached, the remainder of string is appended
|
* delimiter. If max_tokens is reached, the remainder of string is appended
|
||||||
|
|
Loading…
Reference in New Issue