diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-02-07 13:25:00 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-02-07 13:25:00 -0800 |
commit | 0cbde03729a19cad786b2785027ebca4bf099c18 (patch) | |
tree | 3fb190abc6f25477a90c7f987fd66937cf821b33 /pcap-new.c | |
parent | 4f2b0f5befaa75c18a68a6849c759fe94c885727 (diff) |
Use strdup() to mallocate a copy of a string.
Don't incorrectly reimplement strdup(), just use it.
Diffstat (limited to 'pcap-new.c')
-rw-r--r-- | pcap-new.c | 16 |
1 files changed, 2 insertions, 14 deletions
@@ -287,9 +287,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t return -1; } - stringlen = strlen(tmpstring); - - dev->name = (char *)malloc(stringlen + 1); + dev->name = strdup(tmpstring); if (dev->name == NULL) { pcap_fmt_errmsg_for_errno(errbuf, @@ -299,18 +297,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t return -1; } - pcap_strlcpy(dev->name, tmpstring, stringlen); - - dev->name[stringlen] = 0; - /* Create the description */ pcap_snprintf(tmpstring, sizeof(tmpstring) - 1, "%s '%s' %s", PCAP_TEXT_SOURCE_FILE, filename, PCAP_TEXT_SOURCE_ON_LOCAL_HOST); - stringlen = strlen(tmpstring); - - dev->description = (char *)malloc(stringlen + 1); - + dev->description = strdup(tmpstring); if (dev->description == NULL) { pcap_fmt_errmsg_for_errno(errbuf, @@ -320,9 +311,6 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t return -1; } - /* Copy the new device description into the correct memory location */ - pcap_strlcpy(dev->description, tmpstring, stringlen + 1); - pcap_close(fp); } } |