From 2bd7318c1a40cd2f2ae55382be3433ea384e8eff Mon Sep 17 00:00:00 2001 From: blueswir1 Date: Sat, 25 Oct 2008 11:23:27 +0000 Subject: [PATCH 1/1] Replace uses of strndup (a GNU extension) with Qemu pstrdup git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5532 c046a42c-6fe2-441c-8c8c-71466251a162 --- cutils.c | 12 ++++++++++++ hw/bt-hci.c | 2 +- qemu-common.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cutils.c b/cutils.c index 9ef2fa6..8fcb62e 100644 --- a/cutils.c +++ b/cutils.c @@ -50,6 +50,18 @@ char *pstrcat(char *buf, int buf_size, const char *s) return buf; } +/* strdup with a limit */ +char *pstrdup(const char *str, size_t buf_size) +{ + size_t len; + char *buf; + + len = MIN(buf_size, strlen(str)); + buf = qemu_malloc(len); + pstrcpy(buf, len, str); + return buf; +} + int strstart(const char *str, const char *val, const char **ptr) { const char *p, *q; diff --git a/hw/bt-hci.c b/hw/bt-hci.c index 714e726..ab11e49 100644 --- a/hw/bt-hci.c +++ b/hw/bt-hci.c @@ -1814,7 +1814,7 @@ static void bt_submit_hci(struct HCIInfo *info, if (hci->device.lmp_name) free((void *) hci->device.lmp_name); - hci->device.lmp_name = strndup(PARAM(change_local_name, name), + hci->device.lmp_name = pstrdup(PARAM(change_local_name, name), sizeof(PARAM(change_local_name, name))); bt_hci_event_complete_status(hci, HCI_SUCCESS); break; diff --git a/qemu-common.h b/qemu-common.h index cc95fe6..aca2674 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -82,6 +82,7 @@ int qemu_timedate_diff(struct tm *tm); /* cutils.c */ void pstrcpy(char *buf, int buf_size, const char *str); char *pstrcat(char *buf, int buf_size, const char *s); +char *pstrdup(const char *str, size_t buf_size); int strstart(const char *str, const char *val, const char **ptr); int stristart(const char *str, const char *val, const char **ptr); time_t mktimegm(struct tm *tm); -- 1.7.9.5