Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@haydenroche5
Copy link
Collaborator

  • Fix some typos in n_cjson_helpers.c Doxygen comments.
  • Check return value of _SerialReset in retry loop of serialNoteReset.
  • Exclude third party code (e.g. n_md5.c) from coverage report.
  • Remove unnecessary "inLog" code from NotePrint.
  • Get rid of the need for some casting in i2cNoteReset and serialNoteTransaction.
  • Add new unit tests for serialNoteTransaction, serialNoteReset, NoteSetFn, NoteDebug, NoteTransaction hooks, NoteSerial hooks, NotePrint, and NotePrintln.

@haydenroche5 haydenroche5 self-assigned this Jan 11, 2023
@haydenroche5 haydenroche5 requested a review from zfields January 11, 2023 21:46
n_i2c.c Outdated

// Loop to drain all chunks of data that may be ready to transmit to us
int chunklen = 0;
uint32_t chunklen = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
uint32_t chunklen = 0;
uint16_t chunklen = 0;

I'm always leary of changing types.

Moving to unsigned is a good change, and I cannot see any immediate side-effects of uint32_t. However, since you are making the change, perhaps you can select a type that is "guaranteed to be safe", like uint16_t.

The signature for _I2CReceive() is:

const char *NoteI2CReceive(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size, uint32_t *available)

chunklen goes into the Size parameter, which is uint16_t.

As note-c written today, the value in chunklen cannot exceed 127, so there is no problem. That being said, why not play is safe?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's odd that the available parameter returns a uint32_t, which is then loaded into chunklen. 🤔

NoteI2cReceive is executing a callback (beyond our control), so it seems like we should program defensively and also add a bounds check (along with test) around this edge case.

Below (line #266) you could change the logic to protect against it with:

            // Read everything that's left on the module
            chunklen = (available > USHRT_MAX) ? USHRT_MAX : available;

@rayozzie
Copy link
Contributor

rayozzie commented Jan 12, 2023 via email

@haydenroche5
Copy link
Collaborator Author

The reason for “inLog” is self-evident if you were to remove it: NoteTransaction ITSELF does NoteDebug output for transaction debugging, and without the flag we’d go recursive and blow the stack

Correct, but the function in question is NotePrint, not NoteDebug. NoteTransaction should never call NotePrint, from my reading of the code.

@rayozzie
Copy link
Contributor

get rid of the inLog then. it must be historical before NoteDebug was separated from NotePrint

@haydenroche5 haydenroche5 force-pushed the unit_tests branch 2 times, most recently from 0aa8abc to f6d286d Compare January 13, 2023 17:35
- Fix some typos in n_cjson_helpers.c Doxygen comments.
- Check return value of _SerialReset in retry loop of serialNoteReset.
- Exclude third party code (e.g. n_md5.c) from coverage report.
- Get rid of the need for some casting in i2cNoteReset and
serialNoteTransaction.
- The I2C tx/rx hooks expect the buffer size as a uint16_t, which wasn't
respected by the transaction and reset code in n_i2c.c. This commit fixes that.
- Add new unit tests for serialNoteTransaction, serialNoteReset, NoteSetFn,
NoteDebug, NoteTransaction hooks, NoteSerial hooks, NotePrint, and NotePrintln.
@haydenroche5 haydenroche5 merged commit 8f8289e into blues:master Jan 13, 2023
@haydenroche5 haydenroche5 deleted the unit_tests branch January 13, 2023 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants