diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-28 21:43:18 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-28 21:43:18 +0100 |
commit | ad29f57f828f72032403c37cd69f5302e99790ec (patch) | |
tree | 46244cba42301b62b6a17719a81c75d2f06e72e8 | |
parent | 2248b804b1bfb41ba109a1a4220dcc77e42a1fad (diff) | |
download | fastd-ad29f57f828f72032403c37cd69f5302e99790ec.tar fastd-ad29f57f828f72032403c37cd69f5302e99790ec.zip |
fastd_string_stack_dup[n]: use memcpy instead of strcpy when the length of the string is known
Is a bit more optimized and avoids a warning on OpenBSD
-rw-r--r-- | src/fastd.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/fastd.h b/src/fastd.h index b4266ff..3ae856c 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -439,9 +439,12 @@ static inline bool fastd_peer_address_is_v6_ll(const fastd_peer_address_t *addr) /** Duplicates a string, creating a one-element string stack */ static inline fastd_string_stack_t * fastd_string_stack_dup(const char *str) { - fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + strlen(str) + 1, 8)); + size_t str_len = strlen(str); + fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + str_len + 1, 8)); + ret->next = NULL; - strcpy(ret->str, str); + + memcpy(ret->str, str, str_len + 1); return ret; } @@ -450,8 +453,10 @@ static inline fastd_string_stack_t * fastd_string_stack_dup(const char *str) { static inline fastd_string_stack_t * fastd_string_stack_dupn(const char *str, size_t len) { size_t str_len = strnlen(str, len); fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + str_len + 1, 8)); + ret->next = NULL; - strncpy(ret->str, str, str_len); + + memcpy(ret->str, str, str_len); ret->str[str_len] = 0; return ret; |