]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tools: iio: iio_utils: fix digit calculation
authorMatti Vaittinen <mazziesaccount@gmail.com>
Thu, 13 Oct 2022 12:04:04 +0000 (15:04 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Nov 2022 14:56:53 +0000 (23:56 +0900)
commit 1bd92c10b15b6a1691da91a6517710993383eef9 upstream.

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: 49d2f0cbd472 ("tools:iio:iio_utils: implement digit calculation")
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/Y0f+tKCz+ZAIoroQ@dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/iio/iio_utils.c

index 7399eb7f13786f9d2e45d4fb9eef5e6123285ca4..d66b18c54606ab005e5fb8fc3662dc484b8a6381 100644 (file)
@@ -543,6 +543,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++;