Skip to content

Commit

Permalink
Change: Use g_memdup2 when available
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier committed Apr 25, 2023
2 parents 74b0948 + 895d2a9 commit 4557386
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
17 changes: 9 additions & 8 deletions base/networking.c
Expand Up @@ -48,6 +48,13 @@
*/
#define G_LOG_DOMAIN "libgvm base"

#if (GLIB_MAJOR_VERSION >= 2) && (GLIB_MINOR_VERSION >= 67) \
&& (GLIB_MICRO_VERSION >= 3)
#define memdup g_memdup2
#else
#define memdup g_memdup
#endif

/* Global variables */

/* Source interface name eg. eth1. */
Expand Down Expand Up @@ -368,19 +375,13 @@ gvm_resolve_list (const char *name)
{
struct sockaddr_in *addrin = (struct sockaddr_in *) p->ai_addr;
ipv4_as_ipv6 (&(addrin->sin_addr), &dst);
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
list = g_slist_prepend (list, g_memdup (&dst, sizeof (dst)));
#pragma GCC diagnostic pop
list = g_slist_prepend (list, memdup (&dst, sizeof (dst)));
}
else if (p->ai_family == AF_INET6)
{
struct sockaddr_in6 *addrin = (struct sockaddr_in6 *) p->ai_addr;
memcpy (&dst, &(addrin->sin6_addr), sizeof (struct in6_addr));
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
list = g_slist_prepend (list, g_memdup (&dst, sizeof (dst)));
#pragma GCC diagnostic pop
list = g_slist_prepend (list, memdup (&dst, sizeof (dst)));
}
p = p->ai_next;
}
Expand Down
12 changes: 8 additions & 4 deletions util/kb.c
Expand Up @@ -40,6 +40,13 @@
*/
#define G_LOG_DOMAIN "libgvm util"

#if (GLIB_MAJOR_VERSION >= 2) && (GLIB_MINOR_VERSION >= 67) \
&& (GLIB_MICRO_VERSION >= 3)
#define memdup g_memdup2
#else
#define memdup g_memdup
#endif

/**
* @file kb.c
*
Expand Down Expand Up @@ -692,10 +699,7 @@ redis2kbitem_single (const char *name, const redisReply *elt, int force_int)
else
{
item->type = KB_TYPE_STR;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
item->v_str = g_memdup (elt->str, elt->len + 1);
#pragma GCC diagnostic pop
item->v_str = memdup (elt->str, elt->len + 1);
item->len = elt->len;
}

Expand Down

0 comments on commit 4557386

Please sign in to comment.