Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Mar 29, 2022 12:51 UTC (Tue) by jem (subscriber, #24231)In reply to: Handling argc==0 in the kernel by fest3er
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.
Yes, of course. If argc is 0, then the argument vector is empty and only contains the terminating NULL at index 0. You can't expect to find anything of interest in argv[1].
>And when the kernel constructs the argv array, does it use its memory or the user's memory?
The argv array is in the process (user) address space. You can print the address of argv if you are interested to find out where it is located.
