Skip to content

Commit

Permalink
tools: iio: iio_utils: fix digit calculation
Browse files Browse the repository at this point in the history
The iio_utils uses a digit calculation in order to know length of the
file name containing a buffer number. The digit calculation does not
work for number 0.

This leads to allocation of one character too small buffer for the
file-name when file name contains value '0'. (Eg. buffer0).

Fix digit calculation by returning one digit to be present for number
'0'.

Fixes: 096f9b8 ("tools:iio:iio_utils: implement digit calculation")
Signed-off-by: Matti Vaittinen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Cc: <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
M-Vaittinen authored and jic23 committed Oct 17, 2022
1 parent 174dac5 commit 72b2aa3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/iio/iio_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ static int calc_digits(int num)
{
int count = 0;

/* It takes a digit to represent zero */
if (!num)
return 1;

while (num != 0) {
num /= 10;
count++;
Expand Down

0 comments on commit 72b2aa3

Please sign in to comment.