mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 22:08:35 +08:00
drivers/sensors/gnss: Fix integer overflow error
CID 1309501: (#1 of 1): Overflow constant (INTEGER_OVERFLOW) overflow_const: Expression upper->crefs, which is equal to 255, where enable ? 1 : -1 is known to be equal to -1, overflows the type that receives it, an unsigned integer 8 bits wide. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
parent
7e0e4dea75
commit
350f396aa5
1 changed files with 12 additions and 5 deletions
|
@ -168,14 +168,21 @@ static int gnss_activate(FAR struct sensor_lowerhalf_s *lower,
|
|||
int ret = OK;
|
||||
|
||||
nxmutex_lock(&upper->lock);
|
||||
if ((upper->crefs == 0 && enable) || (upper->crefs == 1 && !enable))
|
||||
if ((upper->crefs == 255 && enable) || (upper->crefs == 0 && !enable))
|
||||
{
|
||||
ret = upper->lower->ops->activate(upper->lower, filep, enable);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
if (ret >= 0)
|
||||
else
|
||||
{
|
||||
upper->crefs += enable ? 1 : -1;
|
||||
if ((upper->crefs == 0 && enable) || (upper->crefs == 1 && !enable))
|
||||
{
|
||||
ret = upper->lower->ops->activate(upper->lower, filep, enable);
|
||||
}
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
upper->crefs += enable ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
nxmutex_unlock(&upper->lock);
|
||||
|
|
Loading…
Reference in a new issue