copyout and NULL


(David Robert Olsen) #1

Whenever I try to copyout the last argv argument in execv to the user stack, I keep on hitting a ‘bad memory address’ error. I am pretty sure this is due to the NULL keyword. This happened even when casting NULL to a character pointer.

Am I right to assume this NULL is supposed to be the string-terminator version of NULL? The recitation slides are not very clear about this.


(Geoffrey Challen) #2

NULL is just 0s. How many depends on the type. Strings are terminated with a single NULL (0) byte, while pointers are nulled with four zeros.

You shouldn’t be writing to NULL, although you may be writing the NULL value (i.e, 0).


(David Robert Olsen) #3

As kind of a corollary to this, is it required that the first 4 bytes of the user stack are set to the null value? Or is the example in the slides just an example of padding being used?


(Geoffrey Challen) #4

No. That’s probably a NULL terminator for the argv array. (If not, I’m not sure what it’s for.)