Skip to content

Commit 8f86b34

Browse files
committed
[Fix] Initialize p_parse_packet structure
- in function : begin_parse_dxl_packet - in function : fast_begin_parse_dxl_packet
1 parent 2064453 commit 8f86b34

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/dxl_c/protocol.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ static DXLLibErrorCode_t end_make_dxl2_0_packet(InfoToMakeDXLPacket_t* p_make_pa
332332
DXLLibErrorCode_t begin_parse_dxl_packet(InfoToParseDXLPacket_t* p_parse_packet,
333333
uint8_t protocol_ver, uint8_t* p_param_buf, uint16_t param_buf_capacity)
334334
{
335+
if(p_parse_packet == NULL){
336+
return DXL_LIB_ERROR_NULLPTR;
337+
}
338+
335339
if(param_buf_capacity > 0 && p_param_buf == NULL){
336340
return DXL_LIB_ERROR_NULLPTR;
337341
}
@@ -340,21 +344,24 @@ DXLLibErrorCode_t begin_parse_dxl_packet(InfoToParseDXLPacket_t* p_parse_packet,
340344
return DXL_LIB_ERROR_INVAILD_PROTOCOL_VERSION;
341345
}
342346

347+
memset(p_parse_packet, 0, sizeof(InfoToParseDXLPacket_t));
343348
p_parse_packet->protocol_ver = protocol_ver;
344349
p_parse_packet->p_param_buf = p_param_buf;
345350
p_parse_packet->param_buf_capacity = param_buf_capacity;
346-
// p_parse_packet->recv_param_len = 0;
347-
// p_parse_packet->parse_state = 0;
348351
p_parse_packet->is_init = true;
349352

350353
return DXL_LIB_OK;
351354
}
352355

353356
DXLLibErrorCode_t fast_begin_parse_dxl_packet(InfoToParseDXLPacket_t* p_parse_packet, uint8_t protocol_ver)
354357
{
358+
if (p_parse_packet == NULL)
359+
return DXL_LIB_ERROR_NULLPTR;
360+
355361
if (protocol_ver != 2)
356362
return DXL_LIB_ERROR_INVAILD_PROTOCOL_VERSION;
357363

364+
memset(p_parse_packet, 0, sizeof(InfoToParseDXLPacket_t));
358365
p_parse_packet->protocol_ver = protocol_ver;
359366
p_parse_packet->p_param_buf = nullptr;
360367
p_parse_packet->param_buf_capacity = 0;

src/dxl_c/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdint.h>
2020
#include <stddef.h>
2121
#include <stdbool.h>
22+
#include <cstring>
2223

2324
const int DXL_BROADCAST_ID = 0xFE;
2425

0 commit comments

Comments
 (0)