Skip to content

Commit

Permalink
safe clipclip(int v, int minv, int maxv) : swap(minv, maxv) when (min…
Browse files Browse the repository at this point in the history
…v>maxv)
  • Loading branch information
gitgjogh committed Feb 9, 2016
1 parent 8213286 commit e10519f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libsim/sim_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ int num_leading_zero_bits_u32(uint32_t val)

int clip(int v, int minv, int maxv)
{
v = (v<minv) ? minv : v;
v = (v>maxv) ? maxv : v;
return v;
if (minv > maxv)
mem_swap(&minv, &maxv, sizeof(int), 1);

if (v < minv) return minv;
else if (v > maxv) return maxv;
else return v;
}

/**
Expand Down

0 comments on commit e10519f

Please sign in to comment.