Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Mar 28, 2022 21:41 UTC (Mon) by fest3er (guest, #60379)In reply to: Handling argc==0 in the kernel by matthias
Parent article: Handling argc==0 in the kernel
Hmmm. Off-by-one seems to rear its head here. If argc is 0, then argv[] should contain 0+1 elements, thus only argv[0] exists and should be null and argv[1] is out-of-bounds.
Aside, why are people saying that argv is the same as argv[0]? Isn't argv the address of the array, and argv[0] the address of the zeroeth argument (or null to indicate the end of the array)? Thus, shouldn't argv always be a valid pointer to an array and the array always contain at least the terminating NULL pointer?
And when the kernel constructs the argv array, does it use its memory or the user's memory?
