Dynamically assign MQTT subscription topic on AWS

I try to subscribe to a MQTT topic on AWS using the following code which is used to compose a dynamic MQTT topic based on IMEI

char imei[32] = {'\0',};
modem_info_string_get(MODEM_INFO_IMEI, imei, sizeof(imei));
printk("Modem IMEI: %s \n", imei);
static char settingsString[20] =  "/settings\0";
static char topicString[75];
strcpy(topicString, imei);
strcat(topicString, settingsString);
printk("Subscribe string: %s \n", imei);
printk("Subscribe string length: %d \n", strlen(imei));

const struct aws_iot_topic_data topics_list[APP_TOPICS_COUNT] = {
	[0].str = *topicString,
	[0].len = strlen(*topicString)};

err = aws_iot_subscription_topics_add(topics_list, ARRAY_SIZE(topics_list));
if (err)
{
	printk("aws_iot_subscription_topics_add, error: %d\n", err);
}

The output is this (*** for security reasons) 

Modem IMEI: 351358815046***
Subscribe string: 351358815046***/settings
Subscribe string length: 24

If I now publish a message using AWS MQTT Client the message will not reach the device. The strange thing is if i declare the same variable hard coded using

static char topicString[75] = "351358815046880/settings"

All works as expected and the publish messages get received as expected. 

Is there anything wrong using the strcat function? 

Thanks!

Related