min-protocol / min

The MIN protocol specification and reference implementation
257 stars 88 forks source link

Fix issue #9. MAX_PAYLOAD warning #55

Open 0x3333 opened 1 week ago

0x3333 commented 1 week ago

For context, MAX_PAYLOAD is 255 by default, rx_frame_length is uint8_t, which means that is limited to 255. When compiling, it issues a warning:

/Users/0x3333/Code/g6/deps/min/target/min.c:507:39: warning: comparison is always true due to limited range of data type [-Wtype-limits]
  507 |             if (self->rx_frame_length <= MAX_PAYLOAD) {
      |                                       ^~

This PR checks if MAX_PAYLOAD is different from 255, and if it is, will check the length of the rx packet being received; if not, will just continue receiving, because the buffer is at its maximum size.

rx_frame_state = RECEIVING_PAYLOAD is set by default to simplify the #if, as it will be overwritten if rx packet is bigger anyways.