Skip to content

Commit 72b2aa3

Browse files
M-Vaittinenjic23
authored andcommitted
tools: iio: iio_utils: fix digit calculation
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]>
1 parent 174dac5 commit 72b2aa3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/iio/iio_utils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ static int calc_digits(int num)
547547
{
548548
int count = 0;
549549

550+
/* It takes a digit to represent zero */
551+
if (!num)
552+
return 1;
553+
550554
while (num != 0) {
551555
num /= 10;
552556
count++;

0 commit comments

Comments
 (0)