On Sat, Aug 2, 2025 at 11:02 AM Dan Carpenter <dan.carpenter@xxxxxxxxxx> 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@xxxxxxxxxx> 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@xxxxxxxxx> 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