Commit 2bd7318c1a40cd2f2ae55382be3433ea384e8eff
1 parent
be15b141
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
Showing
3 changed files
with
14 additions
and
1 deletions
cutils.c
| @@ -50,6 +50,18 @@ char *pstrcat(char *buf, int buf_size, const char *s) | @@ -50,6 +50,18 @@ char *pstrcat(char *buf, int buf_size, const char *s) | ||
| 50 | return buf; | 50 | return buf; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | +/* strdup with a limit */ | ||
| 54 | +char *pstrdup(const char *str, size_t buf_size) | ||
| 55 | +{ | ||
| 56 | + size_t len; | ||
| 57 | + char *buf; | ||
| 58 | + | ||
| 59 | + len = MIN(buf_size, strlen(str)); | ||
| 60 | + buf = qemu_malloc(len); | ||
| 61 | + pstrcpy(buf, len, str); | ||
| 62 | + return buf; | ||
| 63 | +} | ||
| 64 | + | ||
| 53 | int strstart(const char *str, const char *val, const char **ptr) | 65 | int strstart(const char *str, const char *val, const char **ptr) |
| 54 | { | 66 | { |
| 55 | const char *p, *q; | 67 | const char *p, *q; |
hw/bt-hci.c
| @@ -1814,7 +1814,7 @@ static void bt_submit_hci(struct HCIInfo *info, | @@ -1814,7 +1814,7 @@ static void bt_submit_hci(struct HCIInfo *info, | ||
| 1814 | 1814 | ||
| 1815 | if (hci->device.lmp_name) | 1815 | if (hci->device.lmp_name) |
| 1816 | free((void *) hci->device.lmp_name); | 1816 | free((void *) hci->device.lmp_name); |
| 1817 | - hci->device.lmp_name = strndup(PARAM(change_local_name, name), | 1817 | + hci->device.lmp_name = pstrdup(PARAM(change_local_name, name), |
| 1818 | sizeof(PARAM(change_local_name, name))); | 1818 | sizeof(PARAM(change_local_name, name))); |
| 1819 | bt_hci_event_complete_status(hci, HCI_SUCCESS); | 1819 | bt_hci_event_complete_status(hci, HCI_SUCCESS); |
| 1820 | break; | 1820 | break; |
qemu-common.h
| @@ -82,6 +82,7 @@ int qemu_timedate_diff(struct tm *tm); | @@ -82,6 +82,7 @@ int qemu_timedate_diff(struct tm *tm); | ||
| 82 | /* cutils.c */ | 82 | /* cutils.c */ |
| 83 | void pstrcpy(char *buf, int buf_size, const char *str); | 83 | void pstrcpy(char *buf, int buf_size, const char *str); |
| 84 | char *pstrcat(char *buf, int buf_size, const char *s); | 84 | char *pstrcat(char *buf, int buf_size, const char *s); |
| 85 | +char *pstrdup(const char *str, size_t buf_size); | ||
| 85 | int strstart(const char *str, const char *val, const char **ptr); | 86 | int strstart(const char *str, const char *val, const char **ptr); |
| 86 | int stristart(const char *str, const char *val, const char **ptr); | 87 | int stristart(const char *str, const char *val, const char **ptr); |
| 87 | time_t mktimegm(struct tm *tm); | 88 | time_t mktimegm(struct tm *tm); |