Menu

#1 wrong logical connective in adc_open function

v1.0 (example)
open
nobody
None
5
2008-01-22
2008-01-22
No

When an ADC channel is opened, there is a check if the ADC channel number is within range, and if the callback is valid (line nr. 78 in file src/HAL/HAL_R5/base/src/adc.c).
The problem is, that there is a logical 'and' between those two checks instead of a logical 'or'. In this case, the function will not return FAIL if the ADC channel number is valid, but the callback is invalid.

Example:
#define NUM_ADC_CHANNELS 4
adcNumber = 3
f = NULL

if ((adcNumber >= NUM_ADC_CHANNELS) && (f == NULL))
return FAIL;

Since adcNumber is smaller than NUM_ADC_CHANNELS, the first part of the if-condition is false, and the return statement will not be executed, although the callback function f is NULL.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB