aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-07-31 16:41:31 -0700
committerGuy Harris <guy@alum.mit.edu>2016-07-31 16:41:31 -0700
commit460ed6a30e7708b0e10d1501cdb5d6165adf1f4d (patch)
tree9185e91ddd8f80005d6a5784d14b8e7bd96593b1
parent55340b77dfc11f469ad10b8e7f90501bef314648 (diff)
Use strdup() to make mallocated copies of strings.
-rw-r--r--pcap-new.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/pcap-new.c b/pcap-new.c
index babebfaa..c3ffd7a3 100644
--- a/pcap-new.c
+++ b/pcap-new.c
@@ -155,18 +155,14 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
/* Delete the old pointer */
free(dev->name);
- dev->name = (char *)malloc(strlen(tmpstring) + 1);
-
+ /* Make a copy of the new device identifier */
+ dev->name = strdup(tmpstring);
if (dev->name == NULL)
{
pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc() failed: %s", pcap_strerror(errno));
return -1;
}
- /* Copy the new device identifier into the correct memory location */
- strlcpy(dev->name, tmpstring, strlen(tmpstring) + 1);
-
-
/* Create the new device description */
if ((dev->description == NULL) || (dev->description[0] == 0))
pcap_snprintf(tmpstring, sizeof(tmpstring) - 1, "%s '%s' %s", PCAP_TEXT_SOURCE_ADAPTER,
@@ -178,17 +174,14 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all
/* Delete the old pointer */
free(dev->description);
- dev->description = (char *)malloc(strlen(tmpstring) + 1);
-
+ /* Make a copy of the description */
+ dev->description = strdup(tmpstring);
if (dev->description == NULL)
{
pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc() failed: %s", pcap_strerror(errno));
return -1;
}
- /* Copy the new device description into the correct memory location */
- strlcpy(dev->description, tmpstring, strlen(tmpstring) + 1);
-
dev = dev->next;
}