-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
drivers/bmp180: fix potential use of uninitialized variable #12568
drivers/bmp180: fix potential use of uninitialized variable #12568
Conversation
This was reported by scan-build
OK. I looked at the context and think it should be fixed differently. The first access to The proper solution would be do error handling in case the I2C communication fails. |
It is quite interesting that There are some extra costs of 16 bytes on ATmega and 24 bytes on Cortex-M platforms to fix this warning. So the question is, whether we could work around this with defines. BTW, when executing the test command, I get dozens of
Have you seen them too? |
The result of the analyzer is 100% correct: |
Yes but this is another problem. I think the proposed fix of this PR is ok for now. Looking at the code, I agree we should do a proper error handling: public functions should return an error code instead of the measurement value. This one should be passed as output parameter. That would be better IMHO but would also be an API change. |
Ups, we have taken look in parallel on that.
This is a very old topic. 95% of our drivers (or even more) do not check the return values of |
Maybe, I can also remove the I2C checks in the read_ut/read_up functions. What do you think ? |
I totally agree, I am a friend of fault tolerance. But this was also discussed already a number of times. |
Ok, let's go with the API change then :) |
What is better, having an error handling or having wrong values? I'm not sure. The error handling in What would be the effect, if error handling is removed completely? The user would get sensor values that make no sense. With a consequent error handling, he would get 0 for sensor data that would at least indicate for pressure that it can't be. |
Sure? My understanding was that this was a bit more involved:
But I cannot remember where I got this. |
Probably, you got this from the discussion in issue #10673 |
Changing the API would be a long term process and is not part of this PR. IMO we could go with this PR and accept the small increase of the code size if can make I think it is not necessary to test since it doesn't change anything critical. But if you want, I can do a short test on ESP8266, I have the BMP180 at hand. |
679a078
to
002a472
Compare
Ah, too late, sorry. But I can revert and provide the refactoring in another PR. |
BTW, the new driver version increases the code size by 128 bytes. |
Oh, I'm really sorry. I hate to put work into something that is not used in the end. @maribu What do you think? Two concerns of mine are
On the other hand, similar sensors like SHT1x, SH3x already implement an API in that way with the only difference that they return temperature and humidity in one call. This would be a further possibility. If we decide to change it now, we should also have a look to |
First: I'm OK with both the suggested alternatives (ignoring the return value of the I2C transfer altogether or adding error handling). However, I'm personally a huge fan of carefully handling things that could go wrong and are not code related. I spend enormous amounts of time trying to debug code where the issue was a broken wire. Error handling for communication errors would prevent this. I think that adding an |
002a472
to
679a078
Compare
@gschorcht, I reverted to the initial version of this PR. I backed up the refactoring with error checking in a separate branch, so it's not lost :) |
OK, let's continue with the little change first. Should we open a tracking issue so we do not forget the pending API change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change that makes "scan-build" happy at a very low price of extra bytes in code size.
Contribution description
This PR is small cleanup in the bmp180 driver implementation. It fixes the use of a potentially uninitialized value in the driver. It was raised by scan-build.
Testing procedure
Run
on master, you get this warning:
warning: 2nd function call argument is an uninitialized value _compute_b5(dev, ut, &b5);
. With this PR, it is fixed.One could also verify that the driver still works
Issues/PRs references
Tick one item in #11852