Skip to content

Commit

Permalink
HID: Zero-initialize pointer members
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
forderud committed Sep 9, 2024
1 parent 01bc7ae commit 395e4a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ bool HID_::setup(USBSetup& setup)
}

HID_::HID_(void) : PluggableUSBModule(2, 1, epType),
rootNode(NULL), descriptorSize(0),
descriptorSize(0),
protocol(HID_REPORT_PROTOCOL), idle(1)
{
epType[0] = EP_TYPE_INTERRUPT_IN;
Expand Down
9 changes: 4 additions & 5 deletions src/HID/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,19 @@ class HID_ : public PluggableUSBModule
private:
uint8_t epType[2];

HIDSubDescriptor* rootNode;
HIDSubDescriptor* rootNode = nullptr;
uint16_t descriptorSize;

uint8_t protocol;
uint8_t idle;

// Buffer pointer to hold the feature data
HIDReport* rootReport;
HIDReport* rootReport = nullptr;
uint16_t reportCount;

Serial_ *dbg;

const char *serial;
Serial_ *dbg = nullptr;

const char *serial = nullptr;
};

// Replacement for global singleton.
Expand Down

0 comments on commit 395e4a9

Please sign in to comment.