|
From: Grant S. <mat...@gm...> - 2022-09-26 20:14:10
|
So I noticed something in my code that looked wrong to me, but valgrind
didn't report anything. I made a small example of it, and still no
findings. I'm sure this code is reading/writing past its array. But valgind
doesn't say anything.
I'm I not understanding something or is this a bug.
Using:
valgrind-3.19.0, gcc 4.8.5, CentOS 7
I also tried
valgrind-3.19.0, gcc 7.3.1, Amazon Linux 2
Here is the code.
------
#include <string.h>
#include <stdio.h>
int main()
{
char retStr[32];
// this is bad right? 40 bytes when above was 32?
memset(retStr, 'F', 40);
// These are "writing" past the allocated memory?
retStr[32] = 'A';
retStr[33] = 'B';
// These should be fine
printf("*********** retStr is %c\n", retStr[30]);
printf("*********** retStr is %c\n", retStr[31]);
// These are reading past allocated memory?
printf("*********** retStr is %c\n", retStr[32]);
printf("*********** retStr is %c\n", retStr[33]);
return 0;
}
---
Compiled:
"gcc filename.cxx"
Ran via this command
"valgrind ./a.out"
|