From d673f274cbb0b9aa06132715cd587899948956be Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Thu, 20 Feb 2020 18:24:04 +0000 Subject: [PATCH] Don't use strndup as old versions of OpenWrt don't seem to have it --- common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common.c b/common.c index 84b31793..228dfec9 100644 --- a/common.c +++ b/common.c @@ -1556,7 +1556,11 @@ int string_update_with_size(char **str, int *flag, char *s, size_t len) { if ((s) && (len)) { if ((len != strlen(*str)) || (strncmp(*str, s, len) != 0)) { free(*str); - *str = strndup(s, len); + //*str = strndup(s, len); // it seems that OpenWrt 12 doesn't have this + char *p = malloc(len + 1); + memcpy(p,s,len); + p[len] = '\0'; + *str = p; *flag = 1; } else { *flag = 0; @@ -1569,7 +1573,11 @@ int string_update_with_size(char **str, int *flag, char *s, size_t len) { } } else { // old string is NULL if ((s) && (len)) { - *str = strndup(s, len); + //*str = strndup(s, len); // it seems that OpenWrt 12 doesn't have this + char *p = malloc(len + 1); + memcpy(p,s,len); + p[len] = '\0'; + *str = p; *flag = 1; } else { // old string is NULL and new string is NULL or length 0