aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-12-28 15:01:21 -0800
committerGuy Harris <guy@alum.mit.edu>2015-12-28 23:01:48 +0000
commit0d2947681c80e5e329b5ad234a672bee36e68163 (patch)
treec92a4bd87f2e05390881c45d2dcb60edc9cd0b11 /epan/ftypes
parentbc13e834cc681c6a01a39d25b125a23950139296 (diff)
Save the results of wmem_strndup(NULL, ...) in a non-const pointer.
That way, we have a non-const pointer to use when freeing it, and don't have to undo the constification with a cast. Rename "has_slash" to "slash", while we're at it, as it's not a Boolean indicating whether the string has a slash, it's either a pointer to the slash in question or NULL if the string has no slash. Change-Id: Ia55b39bddb67c8ca71f7b09ee5eb82efaa3bdf0c Reviewed-on: https://code.wireshark.org/review/12891 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/ftypes')
-rw-r--r--epan/ftypes/ftype-ipv4.c28
-rw-r--r--epan/ftypes/ftype-ipv6.c29
2 files changed, 30 insertions, 27 deletions
diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c
index 4ea6f27a5f..3f0b6f77f3 100644
--- a/epan/ftypes/ftype-ipv4.c
+++ b/epan/ftypes/ftype-ipv4.c
@@ -46,21 +46,21 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_,
guint32 addr;
unsigned int nmask_bits;
- const char *has_slash, *net_str;
- char *addr_str;
+ const char *slash, *net_str;
+ const char *addr_str;
+ char *addr_str_to_free = NULL;
fvalue_t *nmask_fvalue;
- gboolean free_addr_str = FALSE;
/* Look for CIDR: Is there a single slash in the string? */
- has_slash = strchr(s, '/');
- if (has_slash) {
+ slash = strchr(s, '/');
+ if (slash) {
/* Make a copy of the string up to but not including the
* slash; that's the address portion. */
- addr_str = wmem_strndup(NULL, s, has_slash - s);
- free_addr_str = TRUE;
+ addr_str_to_free = wmem_strndup(NULL, s, slash - s);
+ addr_str = addr_str_to_free;
}
else {
- addr_str = (char*)s;
+ addr_str = s;
}
if (!get_host_ipaddr(addr_str, &addr)) {
@@ -68,19 +68,19 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_,
*err_msg = g_strdup_printf("\"%s\" is not a valid hostname or IPv4 address.",
addr_str);
}
- if (free_addr_str)
- wmem_free(NULL, addr_str);
+ if (addr_str_to_free)
+ wmem_free(NULL, addr_str_to_free);
return FALSE;
}
- if (free_addr_str)
- wmem_free(NULL, addr_str);
+ if (addr_str_to_free)
+ wmem_free(NULL, addr_str_to_free);
ipv4_addr_set_net_order_addr(&(fv->value.ipv4), addr);
/* If CIDR, get netmask bits. */
- if (has_slash) {
+ if (slash) {
/* Skip past the slash */
- net_str = has_slash + 1;
+ net_str = slash + 1;
/* XXX - this is inefficient */
nmask_fvalue = fvalue_from_unparsed(FT_UINT32, net_str, FALSE, err_msg);
diff --git a/epan/ftypes/ftype-ipv6.c b/epan/ftypes/ftype-ipv6.c
index 34f619325b..e1093c6b67 100644
--- a/epan/ftypes/ftype-ipv6.c
+++ b/epan/ftypes/ftype-ipv6.c
@@ -36,35 +36,38 @@ ipv6_fvalue_set(fvalue_t *fv, const guint8 *value)
static gboolean
ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg)
{
- const char *has_slash;
- char *addr_str;
+ const char *slash;
+ const char *addr_str;
+ char *addr_str_to_free = NULL;
unsigned int nmask_bits;
fvalue_t *nmask_fvalue;
- gboolean free_addr_str = FALSE;
/* Look for prefix: Is there a single slash in the string? */
- if ((has_slash = strchr(s, '/'))) {
- addr_str = wmem_strndup(NULL, s, has_slash-s);
- free_addr_str = TRUE;
+ slash = strchr(s, '/');
+ if (slash) {
+ /* Make a copy of the string up to but not including the
+ * slash; that's the address portion. */
+ addr_str_to_free = wmem_strndup(NULL, s, slash-s);
+ addr_str = addr_str_to_free;
}
else
- addr_str = (char*)s;
+ addr_str = s;
if (!get_host_ipaddr6(addr_str, &(fv->value.ipv6.addr))) {
if (err_msg != NULL)
*err_msg = g_strdup_printf("\"%s\" is not a valid hostname or IPv6 address.", s);
- if (free_addr_str)
- wmem_free(NULL, addr_str);
+ if (addr_str_to_free)
+ wmem_free(NULL, addr_str_to_free);
return FALSE;
}
- if (free_addr_str)
- wmem_free(NULL, addr_str);
+ if (addr_str_to_free)
+ wmem_free(NULL, addr_str_to_free);
/* If prefix */
- if (has_slash) {
+ if (slash) {
/* XXX - this is inefficient */
- nmask_fvalue = fvalue_from_unparsed(FT_UINT32, has_slash+1, FALSE, err_msg);
+ nmask_fvalue = fvalue_from_unparsed(FT_UINT32, slash+1, FALSE, err_msg);
if (!nmask_fvalue) {
return FALSE;
}