I noticed that if you allocate a char
array
inside of a function like this
void example()
{
char dataBuffer[100] = { 0 };
}
then examine the disassembly of the function with IDA that this actually inserts a call to memset()
in order to initialize the char
array
. Looks something like this after I reversed it
memset(stackPointer + offset + 1, 0, 100);
The raw assembly looks like
addic r3, r1, 0x220
addic r3, r3, 1
clrldi r3, r3, 32
li r4, 0
li r5, 0x64
bl memset
But If I were to change the example()
function to
void example()
{
char dataBuffer[100];
}
Then the call to memset()
is not inserted I noticed when examining the disassembly in IDA.
So basically my question is, if the char
array
is not initialized to zero will it still be safe to work with? For example
void example()
{
char dataBuffer[100];
strcpy(dataBuffer, "Just some random text");
strcat(dataBuffer, "blah blah blah example text\0");//null terminator probably not required as strcpy() appends null terminator and strcat() moves the null terminator to end of string. but whatever
}
Should I expect any UB when writing/reading to the char
array
like this even when it is not initialized to zero with the inserted memset()
that comes along with initializing the char array with = { 0 }
?