* [PATCH] tools: iio: iio_utils: fix digit calculation
@ 2022-10-13 12:04 Matti Vaittinen
2022-10-16 16:37 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Matti Vaittinen @ 2022-10-13 12:04 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Hartmut Knaack, linux-iio,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]
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>
---
tools/iio/iio_utils.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index aadee6d34c74..8d35893b2fa8 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -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++;
base-commit: 4fe89d07dcc2804c8b562f6c7896a45643d34b2f
--
2.37.3
--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND
~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tools: iio: iio_utils: fix digit calculation
2022-10-13 12:04 [PATCH] tools: iio: iio_utils: fix digit calculation Matti Vaittinen
@ 2022-10-16 16:37 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2022-10-16 16:37 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Hartmut Knaack, linux-iio,
linux-kernel
On Thu, 13 Oct 2022 15:04:04 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> 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>
hi Matti
Makes sense.
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
> ---
> tools/iio/iio_utils.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
> index aadee6d34c74..8d35893b2fa8 100644
> --- a/tools/iio/iio_utils.c
> +++ b/tools/iio/iio_utils.c
> @@ -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++;
>
> base-commit: 4fe89d07dcc2804c8b562f6c7896a45643d34b2f
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-16 16:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13 12:04 [PATCH] tools: iio: iio_utils: fix digit calculation Matti Vaittinen
2022-10-16 16:37 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).