From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Colin Ian King <colin.i.king@gmail.com>,
Andy Shevchenko <andy@kernel.org>,
Hans de Goede <hansg@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] media: atomisp: Fix incorrect snprintf format specifiers for signed integers
Date: Sat, 2 Aug 2025 11:59:25 +0200 [thread overview]
Message-ID: <CAHp75VeHvGkPf_OHDNfB3aQ-196HHP0hddnPS6DVJsBsiBAMdg@mail.gmail.com> (raw)
In-Reply-To: <934c7ffa-1386-45a0-a4e7-f2b93cca6370@suswa.mountain>
On Sat, Aug 2, 2025 at 11:02 AM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> On Sat, Aug 02, 2025 at 10:45:49AM +0200, Andy Shevchenko wrote:
> > On Sat, Aug 2, 2025 at 9:32 AM Dan Carpenter <dan.carpenter@linaro.org> wrote:
> > > On Fri, Aug 01, 2025 at 11:57:43PM +0200, Andy Shevchenko wrote:
> > > > On Fri, Aug 1, 2025 at 6:01 PM Colin Ian King <colin.i.king@gmail.com> wrote:
> > > > >
> > > > > There are incorrect %u format specifiers being used to for signed integers,
> > > > > fix this by using %d instead.
> > > >
> > > > Both of them sound to me like the fix of the symptom and not the
> > > > cause. Can we simply make types of the iterators to be unsigned
> > > > instead?
> > >
> > > Making iterator unsigned by default only increases the rate of bugs.
> >
> > How? Please, make sure this is relevant to this case.
>
> You're suggesting that he should change:
>
> - int i, j;
> + unsigned int i, j;
>
> It's just bad advice.
I disagree with this statement. The code varies and in some cases it
should be negative, but those cases are not these one, or you are
talking about _this_ case? If you are talking in general, again I
fully disagree with your statement. One needs to use a common sense.
> Making iterators unsigned makes the code less
> safe. It leads underflow bugs when we do subtraction:
>
> for (i = num - 1; i < limit; i++) {
>
> Now i starts at UINT_MAX. Which I guess is fine in this example...
Depends on the num semantics. The main what one needs is a common sense.
> But it also leads to endless loops in the error handling:
>
> while (i-- >= 0) {
How? Error handling usually takes i > 0. Bad example, try harder.
>
> Making iterators unsigned is a bad habbit
True when use in conjunction with the same statement for signed cases:
"Making iterators signed is a bad habit"
> and it's bad advice in terms
> of the data that we have with regards to bugs.
Disagree. Bugs are common because people do not understand the C
language and its integer rules, wrap-arounds, etc. I believe in many
cases using signed iterators "fix" the bugs due to other variables
also being signed instead of both being unsigned.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2025-08-02 10:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 16:00 Colin Ian King
2025-08-01 21:57 ` Andy Shevchenko
2025-08-02 7:32 ` Dan Carpenter
2025-08-02 8:45 ` Andy Shevchenko
2025-08-02 9:02 ` Dan Carpenter
2025-08-02 9:59 ` Andy Shevchenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHp75VeHvGkPf_OHDNfB3aQ-196HHP0hddnPS6DVJsBsiBAMdg@mail.gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=colin.i.king@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®