nasa / bplib

Apache License 2.0
27 stars 13 forks source link

Cppcheck errors reported in app/bpcat.c #210

Closed jphickey closed 1 year ago

jphickey commented 1 year ago

Describe the bug Cppcheck reports the following issue in app/bpcat.c:

app/bpcat.c:648:86: error: Subtracting pointers that point to different objects [comparePointers]
            status = bplib_send(desc, &msg_buffer, &msg_buffer.content[data_fill_sz] - (uint8_t *)&msg_buffer,
                                                                                     ^
app/bpcat.c:75:14: note: Variable declared here.
    uint8_t  content[BPCAT_DATA_MESSAGE_MAX_SIZE];
             ^
app/bpcat.c:648:52: note: Address of variable taken here.
            status = bplib_send(desc, &msg_buffer, &msg_buffer.content[data_fill_sz] - (uint8_t *)&msg_buffer,
                                                   ^
app/bpcat.c:554:25: note: Variable declared here.
    bpcat_msg_content_t msg_buffer;
                        ^
app/bpcat.c:648:99: note: Address of variable taken here.
            status = bplib_send(desc, &msg_buffer, &msg_buffer.content[data_fill_sz] - (uint8_t *)&msg_buffer,
                                                                                                  ^
app/bpcat.c:648:86: note: Subtracting pointers that point to different objects
            status = bplib_send(desc, &msg_buffer, &msg_buffer.content[data_fill_sz] - (uint8_t *)&msg_buffer,

To Reproduce Execute cppcheck

Expected behavior Should pass cleanly

System observed on: Ubuntu 22.04

Additional context Both types should be uint8_t* however this code might be clearer by using offsetof() instead.

Reporter Info Joseph Hickey, Vantage Systems, Inc.