Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Jan 31, 2022 19:57 UTC (Mon) by marcH (subscriber, #57642)In reply to: Handling argc==0 in the kernel by nybble41
Parent article: Handling argc==0 in the kernel
It's "exactly the same" only if your termination looks like "i != argc" but no one ever does that. Everyone does "i < argc" or something like it. I mean no one writes:
for (int i; i++; i!=argc)
> but using argc instead of checking for NULL is neither necessary nor sufficient to avoid this problem.
I haven't looked at the actual code but if pkexec's loop had used an argc-based termination then the loop would have not run at all.
> int i = 1; do { ... } while (i++ < argc)" to shave off a "redundant" bounds check.)
That's bending over backwards to avoid a simpler for loop. I'm sure you can find some real world and valid cases for this but most of the time people just write a simpler for loop.
