From patchwork Thu Oct 13 12:04:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13005897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9CECC4332F for ; Thu, 13 Oct 2022 12:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbiJMMFC (ORCPT ); Thu, 13 Oct 2022 08:05:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiJMMFA (ORCPT ); Thu, 13 Oct 2022 08:05:00 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE7B303F2; Thu, 13 Oct 2022 05:04:58 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id a25so2098591ljk.0; Thu, 13 Oct 2022 05:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=xKC63qt3cm6YXRHgcntnH0PvtZLR9kcs/isijApz+ls=; b=e7XsURb1RcZi3Nh/LAiEeEg1Ck5uv1klfPu0FDyuB+c6O2VvSpgaaaR+rWiLHAG98D medPItFI58F6F31FmgihXNuTasYDNf56dI6AzsHI5SzsmVqJfjhBbkeMdVnuhsiZIjAB aZsgwozFcen0t9cIFS4LOwv3ruR9/c8eXRo7Xd3QETCc5zhJxQO+0TJKHQ/wNS14A2N6 WfDWq0E9Lk6OIPJOwim2h1UvUWGmzc3nlvA4qxW5+FcPDgY/aLJX8C+cZUMJGmf5UWkO WbFPiMBYtJv7xkYSfJ0Ey1BP01eOv4pMqNK78on2wWupxrFn3F7UulxFyChavfJThCzg qN+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xKC63qt3cm6YXRHgcntnH0PvtZLR9kcs/isijApz+ls=; b=RtSEBqjWyoEGvG/XrjsO4BH+vi7ghkDd5lypKUC7VAsuX+pG5eKVZbv1r/GJ0jwbcl IacNpuKdV2ngnyfC/iAOi17Xef+SDP2G9BRcoGlxTpe8O7nzduY0vPytvOd76Rq9zaJ1 rSpDVrqNb3C/U6sTikYuk6poyo3TJd/p1Jkp4wez7DJ+NL+1hVN/LKdEkqumqcHdkicG snntjgxbSq6WNEGAt4SYTJn2jmYQT5dRIUeFAHfKbWd1Smcsg/ImEjW5O7Ti8CM2f1/i gquw6KZBdMMrcrGiqUKwEavNgUhls2z92vzJqwNbP0eristv2W/GzE7xIg+1zkwjbNKR GYGw== X-Gm-Message-State: ACrzQf28deBbWtZqHL2Tl2vukNWUrsSG4C4gHZMcMRUTotEeRRWUQViz p+00VLMsxtQya9KtsDJVUtM= X-Google-Smtp-Source: AMsMyM5JU59fwYy1esJ9Glo11YJMsAj/PzOiJ4OmVTqXxu80LcZQflZHyLPKeCV6+9mrR94wlku0GQ== X-Received: by 2002:a2e:6d02:0:b0:26a:cf02:40c4 with SMTP id i2-20020a2e6d02000000b0026acf0240c4mr13103360ljc.513.1665662665868; Thu, 13 Oct 2022 05:04:25 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::4]) by smtp.gmail.com with ESMTPSA id 5-20020ac25f05000000b0049d83646ce7sm378761lfq.110.2022.10.13.05.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:04:24 -0700 (PDT) Date: Thu, 13 Oct 2022 15:04:04 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Hartmut Knaack , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tools: iio: iio_utils: fix digit calculation Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 --- tools/iio/iio_utils.c | 4 ++++ 1 file changed, 4 insertions(+) base-commit: 4fe89d07dcc2804c8b562f6c7896a45643d34b2f 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++;