-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MFRC522Extended.cpp:824: warning: ordered comparison of pointer with integer zero #371
Comments
I agree that there is a unclear situation. But I have no overview about this code. Main coding is from JPG-Consulting but he finished his project. Links to lines of code: |
My guess is that it is to check that the pointer is non NULL as you read from/write to the pointed address in case the if condition is true. --> just change (edit - disregard) |
Please consider reopening this issue as it blocks compiling an Arduino sketch with Besides, I think looking at the code shows up a bunch of problems in this area which suggest it has no users and could just be deleted or The prototype allows two optional parameters, both pointers, both defaulting to NULL.
The function body always unconditionally dereferences
I don't know C++, only C, but I assume this is just as invalid in C++? That implies Then we have the two uses which guard the memcpy(3), e.g. if (backData && (backLen > 0)) {
if (*backLen < in.inf.size)
return STATUS_NO_ROOM;
*backLen = in.inf.size;
memcpy(backData, in.inf.data, in.inf.size);
} Given
Similarly for the second case: if (backData && (backLen > 0)) {
if ((*backLen + ackDataSize) > totalBackLen)
return STATUS_NO_ROOM;
memcpy(&(backData[*backLen]), ackData, ackDataSize);
*backLen += ackDataSize;
} We've already saved the original size of @salieff, does this seem accurate to you given you've submitted a patch in the past? |
backLen is a pointer, writing |
Hi @JAY-M-ERICSSON, Yes, that's the problem being fixed. You seem to be taking a quote of the current faulty code as a suggestion for the fix. :-) |
fair point indeed |
Hi everyone,
I'm using Arduino IDE 1.8.16 and MFRC522 v1.4.10, if that matters. This is what's executed on compile:
|
have you modified the library taking into account the suggestion from @RalphCorderoy? |
Ah, my mistake. Didn't read it as careful as I should have. I got it to compile with that fix. |
…ckLen As described here miguelbalboa#371 (comment)
Confirm that. Works fine after change. Also Line 909 the creator of the code already uses the proper comparison. |
Instead we just look if backLen is set. More infos here: miguelbalboa#371
Bump - any chance of getting this fixed? |
I have had this issue when trying to compile the code for a Raspberry Pi Pico W using Earle Philhowers Arduino-Pico core. The fix for me was to change if (backData && (backLen > 0)) { to if (backData && backlen != nullptr)) { at lines 824 and 847. The code now compiles and the sketch runs correctly. |
For esp32 Line: 824 and 847 |
That looks to be equivalent to the fix I suggest in the analysis above: #371 (comment) |
the Hello, I have the same problem with my Arduino IDE. How can I change these lines? |
Hopefully, this comment will stay at the end and put off people who are trying to be helpful by adding yet another copy of the fix described in detail above at #371 (comment) |
The following GCC warning is emitted during compile:
Since
backLen
is a pointer, it will be always positive. However, for fixing it I don't know if it's a bugbackLen != nullptr
or*backLen > 0
orThe same is also in line 847.
The text was updated successfully, but these errors were encountered: