Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Jan 31, 2022 19:42 UTC (Mon) by nybble41 (subscriber, #55106)In reply to: Handling argc==0 in the kernel by marcH
Parent article: Handling argc==0 in the kernel
One could equally well cast this issue as "caused by not checking the first element of the array for the NULL terminator". It's exactly the same error as if you received a NUL-terminated string and started iterating over it from the second element, assuming the string to be non-empty.
I'm in the Pascal-style string/list camp myself—lengths should be explicit—but using argc instead of checking for NULL is neither necessary nor sufficient to avoid this problem. (To illustrate the latter, consider the case of a program making the same non-empty argv assumption and using a loop of the form "int i = 1; do { ... } while (i++ < argc)" to shave off a "redundant" bounds check.)
