fix(vd960DBN): 修复 WCHNET_SocketSend 参数类型不匹配致栈破坏 hard fault
root cause: iot_mqtt_send() 声明 uint16_t slen = len, 传给 WCHNET_SocketSend(..., uint32_t *len) 时取址 &slen。 WCHNET 写 4 字节返回值到 2 字节栈变量 → 破坏相邻栈内容 (返回地址/帧指针) → 函数返回时 hard fault 重启 fix: slen 改为 uint32_t
This commit is contained in:
@@ -292,10 +292,10 @@ static int iot_make_topic(char *out, uint16_t out_len, const char *direction,
|
|||||||
|
|
||||||
/* 发送 MQTT 报文到 broker */
|
/* 发送 MQTT 报文到 broker */
|
||||||
static int iot_mqtt_send(const uint8_t *buf, uint16_t len) {
|
static int iot_mqtt_send(const uint8_t *buf, uint16_t len) {
|
||||||
uint16_t slen = len;
|
uint32_t slen = len; /* 必须是 uint32_t: WCHNET_SocketSend 写 4 字节, uint16_t 会栈破坏致 hard fault */
|
||||||
PRINT("IOT: SocketSend sock=%d len=%d\n", g_iot_socket, len);
|
PRINT("IOT: SocketSend sock=%d len=%lu\n", g_iot_socket, (unsigned long)slen);
|
||||||
uint8_t ret = WCHNET_SocketSend(g_iot_socket, (uint8_t *)buf, &slen);
|
uint8_t ret = WCHNET_SocketSend(g_iot_socket, (uint8_t *)buf, &slen);
|
||||||
PRINT("IOT: SocketSend ret=0x%02X sent=%d\n", ret, slen);
|
PRINT("IOT: SocketSend ret=0x%02X sent=%lu\n", ret, (unsigned long)slen);
|
||||||
return (ret == WCHNET_ERR_SUCCESS) ? 0 : -1;
|
return (ret == WCHNET_ERR_SUCCESS) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user