From 4e5fccee8242f0748259ced0f5c4ff50360e3624 Mon Sep 17 00:00:00 2001 From: nmcdonnell-kx Date: Mon, 22 Mar 2021 10:38:17 +0000 Subject: [PATCH 1/2] Reapply Rian's last-will change without strndup --- src/mqtt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mqtt.c b/src/mqtt.c index 8405610..52c0e9e 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -55,7 +55,10 @@ static char* getCharArrayAsStringFromList(K propValues,int row, const char** val { if ((int)(kK(propValues)[row]->t) == KC) { - *value = strndup((const char *)kC(kK(propValues)[row]),kK(propValues)[row]->n); + // Don't use strndup because it's not supported on early OS X builds + char* str = malloc(kK(propValues)[row]->n); + memcpy(str, kC(kK(propValues)[row]), kK(propValues)[row]->n); + *value = str; return 0; } return errStr; From 48b62066f94c0ac8c570a403181fba5cfea11a6c Mon Sep 17 00:00:00 2001 From: nmcdonnell-kx Date: Mon, 22 Mar 2021 11:01:40 +0000 Subject: [PATCH 2/2] kdb char arrays aren't null terminated --- src/mqtt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mqtt.c b/src/mqtt.c index 52c0e9e..8d65769 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -56,8 +56,9 @@ static char* getCharArrayAsStringFromList(K propValues,int row, const char** val if ((int)(kK(propValues)[row]->t) == KC) { // Don't use strndup because it's not supported on early OS X builds - char* str = malloc(kK(propValues)[row]->n); + char* str = malloc(kK(propValues)[row]->n + 1); memcpy(str, kC(kK(propValues)[row]), kK(propValues)[row]->n); + str[kK(propValues)[row]->n] = '\0'; *value = str; return 0; }