哪个变量导致分段错误?
Which variable cause segmentation fault?
正在尝试调试 MQTT Paho
库中未处理的异常。无法弄清楚哪个确切变量引起分段错误。变量 m 和 ma 不是 NULL。不确定 {...}
在 m->c->connect_state
.
中的含义
如何知道是哪个变量引发了问题?
如何解决这个问题?
函数代码在MQTTClient.c:
int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClient_connectionLost* cl,
MQTTClient_messageArrived* ma, MQTTClient_deliveryComplete* dc)
{
int rc = MQTTCLIENT_SUCCESS;
MQTTClients* m = handle;
FUNC_ENTRY;
Thread_lock_mutex(mqttclient_mutex);
if (m == NULL || ma == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
else
{
m->context = context;
m->cl = cl;
m->ma = ma;
m->dc = dc;
}
Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT_RC(rc);
return rc;
}
这段代码来自Paho官方库:
https://github.com/eclipse/paho.mqtt.c/blob/master/src/MQTTClient.c
以及为什么他们做出这样的分配:
MQTTClients* m = handle;
How to know which exact variable raised the problem?
替换
if (m == NULL || ma == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
暂时与
if (m == NULL)
rc = MQTTCLIENT_FAILURE;
else if (ma == NULL)
rc = MQTTCLIENT_FAILURE;
else if (m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
现在您可以看到是哪个变量导致了问题。
正在尝试调试 MQTT Paho
库中未处理的异常。无法弄清楚哪个确切变量引起分段错误。变量 m 和 ma 不是 NULL。不确定 {...}
在 m->c->connect_state
.
如何知道是哪个变量引发了问题?
如何解决这个问题?
函数代码在MQTTClient.c:
int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClient_connectionLost* cl,
MQTTClient_messageArrived* ma, MQTTClient_deliveryComplete* dc)
{
int rc = MQTTCLIENT_SUCCESS;
MQTTClients* m = handle;
FUNC_ENTRY;
Thread_lock_mutex(mqttclient_mutex);
if (m == NULL || ma == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
else
{
m->context = context;
m->cl = cl;
m->ma = ma;
m->dc = dc;
}
Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT_RC(rc);
return rc;
}
这段代码来自Paho官方库: https://github.com/eclipse/paho.mqtt.c/blob/master/src/MQTTClient.c 以及为什么他们做出这样的分配: MQTTClients* m = handle;
How to know which exact variable raised the problem?
替换
if (m == NULL || ma == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
暂时与
if (m == NULL)
rc = MQTTCLIENT_FAILURE;
else if (ma == NULL)
rc = MQTTCLIENT_FAILURE;
else if (m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
现在您可以看到是哪个变量导致了问题。