LiamBindle / MQTT-C

A portable MQTT C client for embedded systems and PCs alike.
https://liambindle.ca/MQTT-C
MIT License
774 stars 275 forks source link

Function "mqtt_error_str" cause a "Segmentation fault" error! #129

Closed xuyuanwang1993 closed 3 years ago

xuyuanwang1993 commented 3 years ago

I try to use MQTT-C in my C++ project. When I pass “MQTT_OK” in my cpp file to the function "mqtt_error_str", it causes a "Segmentation fault" error.

/Test/ const char* mqtt_error_str(enum MQTTErrors error) { printf("%d %d \r\n",error==MQTT_OK,(error-MQTT_ERROR_UNKNOWN)==(MQTT_OK-MQTT_ERROR_UNKNOWN)); int offset = error - MQTT_ERROR_UNKNOWN; if (offset >= 0) { return MQTT_ERRORS_STR[offset]; } else if (error == 0) { return "MQTT_ERROR: Buffer too small."; } else if (error > 0) { return "MQTT_OK"; } else { return MQTT_ERRORS_STR[0]; } }

/Output/ 1 0

/Environment/ gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) x86_64-linux-gnu