Use g_strndup instead of strndup in asyncns.c, fixes LM-129
authorMikael Hallendal <micke@imendio.com>
Thu, 28 Aug 2008 13:48:06 +0200
changeset 488 f53888f07dcf
parent 484 834033c54bb2
child 489 e1defb50be65
Use g_strndup instead of strndup in asyncns.c, fixes LM-129 Switched to use g_strndup and remove the internal version of strndup from asyncns.c. Fixes problem where strndup exists.
loudmouth/asyncns.c
--- a/loudmouth/asyncns.c	Thu Aug 28 13:34:36 2008 +0200
+++ b/loudmouth/asyncns.c	Thu Aug 28 13:48:06 2008 +0200
@@ -21,6 +21,7 @@
 
 /*#undef HAVE_PTHREAD */
 
+#include <glib.h>
 #include <assert.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -154,27 +155,6 @@
     int ret;
 } res_response_t;
 
-#ifndef HAVE_STRNDUP
-
-static char *strndup(const char *s, size_t l) {
-    size_t a;
-    char *n;
-
-    a = strlen(s);
-    if (a > l)
-        a = l;
-
-    if (!(n = malloc(a+1)))
-        return NULL;
-
-    strncpy(n, s, a);
-    n[a] = 0;
-
-    return n;
-}
-
-#endif
-
 static int fd_nonblock(int fd) {
     int i;
     assert(fd >= 0);
@@ -750,10 +730,10 @@
             q->ret = ni_resp->ret;
 
             if (ni_resp->hostlen)
-                q->host = strndup((const char*) ni_resp + sizeof(nameinfo_response_t), ni_resp->hostlen-1);
+                q->host = g_strndup((const char*) ni_resp + sizeof(nameinfo_response_t), (gsize)ni_resp->hostlen-1);
 
             if (ni_resp->servlen)
-                q->serv = strndup((const char*) ni_resp + sizeof(nameinfo_response_t) + ni_resp->hostlen, ni_resp->servlen-1);
+                q->serv = g_strndup((const char*) ni_resp + sizeof(nameinfo_response_t) + ni_resp->hostlen, (gsize)ni_resp->servlen-1);
                     
 
             complete_query(asyncns, q);
@@ -1093,8 +1073,8 @@
 
     asyncns_freeaddrinfo(q->addrinfo);
     free(q->addrinfo);
-    free(q->host);
-    free(q->serv);
+    g_free(q->host);
+    g_free(q->serv);
 
     asyncns->n_queries--;
     free(q);