Skip to content

Commit

Permalink
drivers/sensors/gnss: Fix integer overflow error
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
JianyuWang0623 authored and xiaoxiang781216 committed Jan 7, 2025
1 parent 7e0e4de commit 350f396
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/sensors/gnss_uorb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 350f396

Please sign in to comment.