Skip to content

Commit 395e4a9

Browse files
committed
HID: Zero-initialize pointer members
I'm new to Arduino development, so I'm not sure if variable are zero-initialized by default. Regardless, it's often regarded good practice to explicitly zero-initialize pointers to reduce risk of treating uninitialized pointers as valid.
1 parent 01bc7ae commit 395e4a9

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/HID/HID.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool HID_::setup(USBSetup& setup)
266266
}
267267

268268
HID_::HID_(void) : PluggableUSBModule(2, 1, epType),
269-
rootNode(NULL), descriptorSize(0),
269+
descriptorSize(0),
270270
protocol(HID_REPORT_PROTOCOL), idle(1)
271271
{
272272
epType[0] = EP_TYPE_INTERRUPT_IN;

src/HID/HID.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,19 @@ class HID_ : public PluggableUSBModule
141141
private:
142142
uint8_t epType[2];
143143

144-
HIDSubDescriptor* rootNode;
144+
HIDSubDescriptor* rootNode = nullptr;
145145
uint16_t descriptorSize;
146146

147147
uint8_t protocol;
148148
uint8_t idle;
149149

150150
// Buffer pointer to hold the feature data
151-
HIDReport* rootReport;
151+
HIDReport* rootReport = nullptr;
152152
uint16_t reportCount;
153153

154-
Serial_ *dbg;
155-
156-
const char *serial;
154+
Serial_ *dbg = nullptr;
157155

156+
const char *serial = nullptr;
158157
};
159158

160159
// Replacement for global singleton.

0 commit comments

Comments
 (0)