Skip to content

Commit 0035601

Browse files
Maldus512Jacajack
authored andcommitted
Explicit initialization of variables
1 parent 6c451f3 commit 0035601

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

include/lightmodbus/master.impl.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const uint8_t modbusMasterDefaultFunctionCount = sizeof(modbusMasterDefaultFunct
6868
\param dataCallback Callback function for handling incoming data (may be required by used parsing functions)
6969
\param exceptionCallback Callback function for handling slave exceptions (optional)
7070
\param allocator Memory allocator to be used (see \ref modbusDefaultAllocator()) (required)
71-
\param functions Pointer to an array of supported function handlers (required).
71+
\param functions Pointer to an array of supported function handlers (required).
7272
The lifetime of this array must not be shorter than the lifetime of the master.
7373
\param functionCount Number of elements in the `functions` array (required)
7474
\returns MODBUS_NO_ERROR() on success
@@ -144,7 +144,7 @@ LIGHTMODBUS_RET_ERROR modbusEndRequestRTU(ModbusMaster *status, uint8_t address)
144144
&status->request.data[0],
145145
status->request.length,
146146
address);
147-
147+
148148
if (err != MODBUS_OK)
149149
return MODBUS_MAKE_ERROR(MODBUS_ERROR_SOURCE_GENERAL, err);
150150

@@ -165,7 +165,7 @@ LIGHTMODBUS_RET_ERROR modbusBeginRequestTCP(ModbusMaster *status)
165165
\brief Finalizes a Modbus TCP request
166166
\param transactionID Modbus TCP transaction identifier
167167
\param unitID Modbus TCP Unit ID
168-
\returns MODBUS_GENERAL_ERROR(LENGTH) if the allocated frame has invalid length
168+
\returns MODBUS_GENERAL_ERROR(LENGTH) if the allocated frame has invalid length
169169
\returns MODBUS_NO_ERROR() on success
170170
*/
171171
LIGHTMODBUS_RET_ERROR modbusEndRequestTCP(ModbusMaster *status, uint16_t transactionID, uint8_t unitID)
@@ -208,7 +208,7 @@ LIGHTMODBUS_RET_ERROR modbusParseResponsePDU(
208208
return MODBUS_REQUEST_ERROR(LENGTH);
209209
if (!responseLength || responseLength > MODBUS_PDU_MAX)
210210
return MODBUS_RESPONSE_ERROR(LENGTH);
211-
211+
212212
uint8_t function = response[0];
213213

214214
// Handle exception frames
@@ -265,9 +265,9 @@ LIGHTMODBUS_RET_ERROR modbusParseResponseRTU(
265265
uint16_t responseLength)
266266
{
267267
// Unpack request
268-
const uint8_t *requestPDU;
269-
uint16_t requestPDULength;
270-
uint8_t requestAddress;
268+
const uint8_t *requestPDU = NULL;
269+
uint16_t requestPDULength = 0;
270+
uint8_t requestAddress = 0;
271271
ModbusError err = modbusUnpackRTU(
272272
request,
273273
requestLength,
@@ -294,7 +294,7 @@ LIGHTMODBUS_RET_ERROR modbusParseResponseRTU(
294294
&responsePDU,
295295
&responsePDULength,
296296
&responseAddress);
297-
297+
298298
if (err != MODBUS_OK)
299299
return MODBUS_MAKE_ERROR(MODBUS_ERROR_SOURCE_RESPONSE, err);
300300

@@ -361,7 +361,7 @@ LIGHTMODBUS_RET_ERROR modbusParseResponseTCP(
361361
&responsePDULength,
362362
&responseTransactionID,
363363
&responseUnitID);
364-
364+
365365
if (err != MODBUS_OK)
366366
return MODBUS_MAKE_ERROR(MODBUS_ERROR_SOURCE_RESPONSE, err);
367367

include/lightmodbus/slave.impl.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void modbusSlaveDestroy(ModbusSlave *status)
111111
response frame is going to be discarded (when the request was broadcast).
112112
113113
\warning This function expects ModbusSlave::response::pduOffset and
114-
ModbusSlave::response::padding to be set properly! If you're looking for a
114+
ModbusSlave::response::padding to be set properly! If you're looking for a
115115
function to manually build an exception please use modbusBuildExceptionPDU(),
116116
modbusBuildExceptionRTU() or modbusBuildExceptionTCP()
117117
*/
@@ -147,7 +147,7 @@ LIGHTMODBUS_RET_ERROR modbusBuildExceptionPDU(
147147
{
148148
status->response.pduOffset = 0;
149149
status->response.padding = 0;
150-
150+
151151
ModbusErrorInfo err = modbusBuildException(status, function, code);
152152
if (!modbusIsOk(err))
153153
return err;
@@ -176,17 +176,17 @@ LIGHTMODBUS_RET_ERROR modbusBuildExceptionRTU(
176176

177177
status->response.pduOffset = MODBUS_RTU_PDU_OFFSET;
178178
status->response.padding = MODBUS_RTU_ADU_PADDING;
179-
179+
180180
ModbusErrorInfo errinfo = modbusBuildException(status, function, code);
181-
181+
182182
if (!modbusIsOk(errinfo))
183183
return errinfo;
184184

185185
ModbusError err = modbusPackRTU(
186186
&status->response.data[0],
187187
status->response.length,
188188
address);
189-
189+
190190
// There's literally no reason for modbusPackRTU()
191191
// to return MODBUS_ERROR_LENGTH here
192192
(void) err;
@@ -196,7 +196,7 @@ LIGHTMODBUS_RET_ERROR modbusBuildExceptionRTU(
196196

197197
/**
198198
\brief Builds a Modbus TCP exception
199-
\param transactionID transaction ID
199+
\param transactionID transaction ID
200200
\param unitID unit ID to be reported in the exception
201201
\param function function that reported the exception
202202
\param code Modbus exception code
@@ -213,9 +213,9 @@ LIGHTMODBUS_RET_ERROR modbusBuildExceptionTCP(
213213
{
214214
status->response.pduOffset = MODBUS_TCP_PDU_OFFSET;
215215
status->response.padding = MODBUS_TCP_ADU_PADDING;
216-
216+
217217
ModbusErrorInfo errinfo = modbusBuildException(status, function, code);
218-
218+
219219
if (!modbusIsOk(errinfo))
220220
return errinfo;
221221

@@ -240,10 +240,10 @@ LIGHTMODBUS_RET_ERROR modbusBuildExceptionTCP(
240240
\returns Any errors from parsing functions
241241
242242
\warning This function expects ModbusSlave::response::pduOffset and
243-
ModbusSlave::response::padding to be set properly! If you're looking for a
243+
ModbusSlave::response::padding to be set properly! If you're looking for a
244244
function to parse PDU and generate a PDU response, please use modbusParseRequestPDU() instead.
245245
246-
\warning The response frame can only be accessed if modbusIsOk() called
246+
\warning The response frame can only be accessed if modbusIsOk() called
247247
on the return value of this function evaluates to true.
248248
*/
249249
LIGHTMODBUS_RET_ERROR modbusParseRequest(ModbusSlave *status, const uint8_t *request, uint8_t requestLength)
@@ -266,7 +266,7 @@ LIGHTMODBUS_RET_ERROR modbusParseRequest(ModbusSlave *status, const uint8_t *req
266266
\returns MODBUS_REQUEST_ERROR(LENGTH) if length of the frame is invalid
267267
\returns Any errors from parsing functions
268268
269-
\warning The response frame can only be accessed if modbusIsOk() called
269+
\warning The response frame can only be accessed if modbusIsOk() called
270270
on the return value from this function evaluates to true.
271271
272272
\warning The `requestLength` argument is of type `uint8_t` and not `uint16_t`
@@ -293,15 +293,15 @@ LIGHTMODBUS_RET_ERROR modbusParseRequestPDU(ModbusSlave *status, const uint8_t *
293293
\returns MODBUS_GENERAL_ERROR(LENGTH) if the resulting response frame has invalid length
294294
\returns Any errors from parsing functions
295295
296-
\warning The response frame can only be accessed if modbusIsOk() called
296+
\warning The response frame can only be accessed if modbusIsOk() called
297297
on the return value of this function evaluates to true.
298298
*/
299299
LIGHTMODBUS_RET_ERROR modbusParseRequestRTU(ModbusSlave *status, uint8_t slaveAddress, const uint8_t *request, uint16_t requestLength)
300300
{
301301
// Unpack the request
302-
const uint8_t *pdu;
303-
uint16_t pduLength;
304-
uint8_t requestAddress;
302+
const uint8_t *pdu = NULL;
303+
uint16_t pduLength = 0;
304+
uint8_t requestAddress = 0;
305305
ModbusError err = modbusUnpackRTU(
306306
request,
307307
requestLength,
@@ -323,7 +323,7 @@ LIGHTMODBUS_RET_ERROR modbusParseRequestRTU(ModbusSlave *status, uint8_t slaveAd
323323
modbusBufferModeRTU(&status->response);
324324
if (!modbusIsOk(errinfo = modbusParseRequest(status, pdu, pduLength)))
325325
return errinfo;
326-
326+
327327
if (status->response.length)
328328
{
329329
// Discard any response frames if the request
@@ -343,7 +343,7 @@ LIGHTMODBUS_RET_ERROR modbusParseRequestRTU(ModbusSlave *status, uint8_t slaveAd
343343
if (err != MODBUS_OK)
344344
return MODBUS_MAKE_ERROR(MODBUS_ERROR_SOURCE_GENERAL, err);
345345
}
346-
346+
347347
return MODBUS_NO_ERROR();
348348
}
349349

@@ -356,7 +356,7 @@ LIGHTMODBUS_RET_ERROR modbusParseRequestRTU(ModbusSlave *status, uint8_t slaveAd
356356
\returns MODBUS_GENERAL_ERROR(LENGTH) if the resulting response frame has invalid length
357357
\returns Any errors from parsing functions
358358
359-
\warning The response frame can only be accessed if modbusIsOk() called
359+
\warning The response frame can only be accessed if modbusIsOk() called
360360
on the return value of this function evaluates to true.
361361
*/
362362
LIGHTMODBUS_RET_ERROR modbusParseRequestTCP(ModbusSlave *status, const uint8_t *request, uint16_t requestLength)
@@ -377,7 +377,7 @@ LIGHTMODBUS_RET_ERROR modbusParseRequestTCP(ModbusSlave *status, const uint8_t *
377377

378378
if (err != MODBUS_OK)
379379
return MODBUS_MAKE_ERROR(MODBUS_ERROR_SOURCE_REQUEST, err);
380-
380+
381381
// Parse the request
382382
ModbusErrorInfo errinfo;
383383
modbusBufferModeTCP(&status->response);

0 commit comments

Comments
 (0)