I am trying to zero-out an entire char pointer. If I perform the statement:
memset(myCharPointer, 0, sizeof(myCharPointer));
it only zeros-out the first 4 bytes because that is the size of a char pointer on my system.
So how can I ensure that the data is completely set to 0? Setting it to NULL does not wipe out the entire char pointer.
sizeof(myCharPointer) is going to give you a sizeof(char*), which is the size of a pointer, which is usually four bytes. A sizeof(char) is going to give you 1 byte.
To do the memset you need to know how long your data is. e.g.,
memset(myCharPointer, 0, myCharPointerLen);
if you know the length of the char array you are pointing to you can do this:
memset(myCharPointer, 0, sizeof(*myCharPointer) * length);
Also, I believe you should use the sizeof the pointer contents instead of that of the pointer itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With