safer string copy

This commit is contained in:
iceman1001 2020-01-04 16:29:17 +01:00
commit 3b792f8b04
2 changed files with 7 additions and 7 deletions

View file

@ -918,13 +918,13 @@ void strcreplace(char *buf, size_t len, char from, char to) {
} }
} }
char *strmcopy(const char *buf) { char *strmcopy(const char *src) {
char *str = (char *) calloc(strlen(buf) + 1, sizeof(uint8_t)); char *dest = (char *) calloc(strlen(src) + 1, sizeof(uint8_t));
if (str != NULL) { if (dest != NULL) {
memset(str, 0, strlen(buf) + 1); memset(dest, 0, strlen(src) + 1);
strcpy(str, buf); strncat(dest, src, strlen(src));
} }
return str; return dest;
} }
/** /**

View file

@ -99,6 +99,6 @@ bool str_endswith(const char *s, const char *suffix); // check for suffix in
void clean_ascii(unsigned char *buf, size_t len); void clean_ascii(unsigned char *buf, size_t len);
void strcleanrn(char *buf, size_t len); void strcleanrn(char *buf, size_t len);
void strcreplace(char *buf, size_t len, char from, char to); void strcreplace(char *buf, size_t len, char from, char to);
char *strmcopy(const char *buf); char *strmcopy(const char *src);
int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str); int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
#endif #endif