Skip to content

Commit bad2d9a

Browse files
committed
removed VLAs since those are bad, apparently
1 parent 8f3e56f commit bad2d9a

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

fw/v24/inc/hdlc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ extern "C" {
2222

2323
#define CRC16_CCITT_INIT_VAL 0xFFFF
2424

25+
/* Max size of an HDLC message (255 for now since I haven't seen longer ones yet) */
26+
#define HDLC_MAX_FRAME_SIZE_BYTES 255U
27+
2528
/* Control Field Bytes */
2629
#define HDLC_CTRL_RR 0x01 // Receive Ready
2730
#define HDLC_CTRL_UI 0x03 // Unnumbered Information

fw/v24/src/hdlc.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ void hdlcEncodeAndSendFrame(const uint8_t *data, const uint8_t len)
134134
// Calculate FCS of message
135135
uint16_t fcs = crc16(data, len);
136136
// Append
137-
uint8_t frame[len + 2];
137+
uint8_t frame[HDLC_MAX_FRAME_SIZE_BYTES];
138138
memcpy(&frame, data, len);
139139
frame[len] = low(fcs);
140140
frame[len + 1] = high(fcs);
141141
// Trace
142142
#ifdef TRACE_HDLC
143-
uint8_t hexStrBuf[(len + 2)*4];
143+
uint8_t hexStrBuf[HDLC_MAX_FRAME_SIZE_BYTES * 4];
144144
HexArrayToStr((char*)hexStrBuf, frame, len + 2);
145145
log_trace("Encoded HDLC: %s", hexStrBuf);
146146
#endif
147147
// See if we need to escape anything
148148
uint8_t escapes = HDLCGetEscapesReq(frame, len + 2);
149149
if (escapes)
150150
{
151-
uint8_t escFrame[len + 2 + escapes];
151+
uint8_t escFrame[HDLC_MAX_FRAME_SIZE_BYTES];
152152
if (HDLCEscape(escFrame, frame, len + 2) != escapes)
153153
{
154154
log_error("Didn't escape the bytes we expected!");
@@ -212,7 +212,7 @@ void HDLCSendRR()
212212
void HDLCSendUI(uint8_t *msgData, uint8_t len)
213213
{
214214
// We need 2 extra bytes for address and control
215-
uint8_t data[len + 2];
215+
uint8_t data[HDLC_MAX_FRAME_SIZE_BYTES];
216216
data[0] = peerAddress;
217217
data[1] = HDLC_CTRL_UI;
218218
memcpy(&data[2], msgData, len);
@@ -355,7 +355,7 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
355355
{
356356
// Debug print hex buffer
357357
#ifdef TRACE_HDLC
358-
uint8_t hexStrBuf[rawLen * 4];
358+
uint8_t hexStrBuf[HDLC_MAX_FRAME_SIZE_BYTES * 4];
359359
#endif
360360

361361
// Incremenet total frames processed
@@ -366,7 +366,7 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
366366
log_trace("Processing %d-byte HDLC message:%s", rawLen, hexStrBuf);
367367
#endif
368368
// Escape
369-
uint8_t msg[rawLen];
369+
uint8_t msg[HDLC_MAX_FRAME_SIZE_BYTES];
370370
uint8_t len = rawLen - HDLCUnescape(msg, rawMsg, rawLen);
371371
#ifdef TRACE_HDLC
372372
if (len != rawLen)
@@ -380,11 +380,11 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
380380
uint8_t msg_ctrl = msg[1];
381381
// Data is bytes 2 to len-2 so buffer size is 4 less
382382
uint8_t data_len = len - 4;
383-
uint8_t msg_data[data_len];
383+
/*uint8_t msg_data[HDLC_MAX_FRAME_SIZE_BYTES];
384384
memset(msg_data, 0, data_len);
385-
memcpy(msg_data, &msg[2], (data_len) * sizeof(uint8_t));
385+
memcpy(msg_data, &msg[2], (data_len) * sizeof(uint8_t));*/
386386
#ifdef TRACE_HDLC
387-
printHexArray((char*)hexStrBuf, msg_data, data_len);
387+
printHexArray((char*)hexStrBuf, msg + 2U, data_len);
388388
log_trace("Msg data:%s", hexStrBuf);
389389
#endif
390390
// Calculate expected FCS by getting the entire message minus the FCS
@@ -433,7 +433,7 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
433433
log_info("Got UI frame (len: %d)", data_len);
434434
hdlcLastRx = HAL_GetTick();
435435
// Write frame to VCP
436-
VCPWriteP25Frame(msg_data, data_len);
436+
VCPWriteP25Frame(msg + 2U, data_len);
437437
break;
438438
default:
439439
log_warn("Unhandled HDLC control type %02X", msg_ctrl);

fw/v24/src/vcp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void VCPRxCallback()
237237
log_debug("Sending UI frame of length %d via HDLC", vcpRxMsgLength - offset - 2U);
238238
#endif
239239
#ifdef TRACE_VCP
240-
uint8_t hexStrBuf[(vcpRxMsgLength - offset - 2U)*4U];
240+
uint8_t hexStrBuf[VCP_MAX_MSG_LENGTH_BYTES * 4U];
241241
HexArrayToStr((char*)hexStrBuf, &vcpRxMsg[offset + 2U], vcpRxMsgLength - offset - 2U);
242242
log_trace("P25 Frame: %s", hexStrBuf);
243243
#endif
@@ -428,7 +428,7 @@ bool VCPWriteAck(uint8_t cmd)
428428
bool VCPWriteP25Frame(const uint8_t *data, uint16_t len)
429429
{
430430
// Start byte, length byte, cmd byte, and a 0x00 pad to maintain dvm compliance
431-
uint8_t buffer[len + 4];
431+
uint8_t buffer[VCP_MAX_MSG_LENGTH_BYTES];
432432
buffer[0] = DVM_SHORT_FRAME_START;
433433
buffer[1] = (uint8_t)len + 4;
434434
buffer[2] = CMD_P25_DATA;
@@ -440,7 +440,7 @@ bool VCPWriteP25Frame(const uint8_t *data, uint16_t len)
440440
log_debug("Writing P25 frame of length %d to VCP", len);
441441
#endif
442442
#ifdef TRACE_VCP
443-
uint8_t hexStrBuf[(len+3)*4];
443+
uint8_t hexStrBuf[VCP_MAX_MSG_LENGTH_BYTES * 4];
444444
printHexArray((char*)hexStrBuf, buffer, len+3);
445445
log_trace("Sending %s", hexStrBuf);
446446
#endif
@@ -469,7 +469,7 @@ void sendVersion()
469469

470470
// HW description
471471
uint8_t count = 21;
472-
for (uint8_t i = 0U; i < sizeof(HARDWARE_STRING); i++, count++)
472+
for (uint8_t i = 0U; i < (uint8_t)sizeof(HARDWARE_STRING); i++, count++)
473473
reply[count] = HARDWARE_STRING[i];
474474

475475
// Total length

0 commit comments

Comments
 (0)