[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with g++ in linux
From: |
Paul Pluzhnikov |
Subject: |
Re: Problem with g++ in linux |
Date: |
15 Jul 2004 23:04:48 -0700 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence) |
Robert Heller <heller@deepsoft.com> writes:
> Consider this code (which contains a bug!):
>
> char *pointer;
>
> pointer = new[strlen("Hello World")];
> strcpy(pointer,"Hello World");
>
> This code will likely work just fine on a big-endian system (such as a
> Sparc), but will in fact trash the heap on a little-endian system (such
> as a ix86).
This code will trash heap on a big-endian system to *exactly*
the same extent as on a little-endian one.
In fact, this is one example where trashing heap will almost never
result in any visible effect (crash), because you are copying 12
bytes into 11-byte block, but most new/malloc implementations will
*actually* allocate 16 bytes.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.