This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52213] Add chunk of memory if array is size is divisable with 8
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 12 Feb 2012 13:44:17 +0000
- Subject: [Bug c++/52213] Add chunk of memory if array is size is divisable with 8
- Auto-submitted: auto-generated
- References: <bug-52213-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52213
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-12 13:44:17 UTC ---
Please provide *complete* testcases, this code is missing <stdio.h> and
<string.h>, since you already wrote it so it compiles why should we have to add
headers again to test it?
(In reply to comment #0)
> <code>
> int main(){
>
> for (int i = 1; i < 100; i++){
> char* name = new char[i];
the array elements will be uninitialized
> for (int j=0; j<i; j++) {name[j] = '1';}
> int length = strlen(name);
This is undefined behaviour, there is no null terminator in the array, how is
strlen supposed to find the length?