summaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorMatti Vaittinen <mazziesaccount@gmail.com>2022-10-13 15:04:04 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-11-03 23:56:53 +0900
commitcb972e6d01efaccdb5ef89eeb6a0ea269719c2be (patch)
tree5d243994d67fced2fc8eae636ce48a31910dbfa4 /tools/iio
parent8f1cd9633d1f21efc13e8fc75be8f2b6bb85e38c (diff)
downloadlinux-stable-cb972e6d01efaccdb5ef89eeb6a0ea269719c2be.tar.gz
linux-stable-cb972e6d01efaccdb5ef89eeb6a0ea269719c2be.tar.bz2
linux-stable-cb972e6d01efaccdb5ef89eeb6a0ea269719c2be.zip
tools: iio: iio_utils: fix digit calculation
commit 72b2aa38191bcba28389b0e20bf6b4f15017ff2b 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: 096f9b862e60 ("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>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/iio_utils.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 7399eb7f1378..d66b18c54606 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -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++;