Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sanity check for SPI dataBitLength #1391

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer

// get data bit length
int databitLength = pConfig[ SpiConnectionSettings::FIELD___databitLength ].NumericByRef().s4;
if (databitLength <= 0) databitLength = 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdrianSoundy wouldn't be better to throw a bad argument exception instead of "fixing" the value?
I mean, as it is it works, of course, but the developer is not aware that he has made a mistake or set it to a wrong value.

That's the usual procedure throughout the code base and it's done in a number of places.

From what I could found (I've only worked with 8 and 16 bits) but the data can be from 8 to 16. I don't know if ESP32 can handle anything in the between...

So I suggest that the check is made for a valid number >= 8 and <= 16 (or just 8 and 16 to keep it simple) and throw an exception on invalid argument. What do you think?

if ( data16 ) databitLength = 16;

// dereference the write and read buffers from the arguments
Expand Down