public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: corey taylor <corey.taylor@gmail.com>
To: sokolhacker@mail.ru
Cc: gcc-help@gcc.gnu.org
Subject: Re: bug?
Date: Fri, 26 Aug 2005 01:06:00 -0000	[thread overview]
Message-ID: <2e393d08050825180662798dbc@mail.gmail.com> (raw)
In-Reply-To: <430E7F43.8060301@mail.ru>

Alexey,

Array bounds checks are not performed in C or C++.

You are writing to memory outside of the array, and it is an error in
the code.  You probably do not crash because the program is simple.

cout does not know the size of the array.  It only sees a char* and
keeps looking forward 1 byte at a time until a 0 is found.

corey

On 8/25/05, Alexey Sokolov <sokolhacker@mail.ru> wrote:
> Hallo!
> /**************************/
> //example file "example.cpp"
> //begin
> #include <iostream.h>
> 
> main()
> {
>          char name[1]; //1 byte(!)
>          name[0]='1';
>          name[1]='2';
>          name[2]='3';
>          name[3]='4';
>          name[4]='\0';
>          cout << name << "\n";
> }
> //end
> /**************************/
> 
> $g++ example.cpp
> $./a.out
> 1234
> 
> 1,2,3,4 and '\0' = 5 byte!
> 5 byte != 1 byte (char name[1];)!
> 
> But why? Forgive for English, I am simple Russian =)
> 
> --
> #gcc --version
> gcc (GCC) 3.4.2 [FreeBSD] 20040728
> 
>

  reply	other threads:[~2005-08-26  1:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-25 23:33 bug? Alexey Sokolov
2005-08-26  1:06 ` corey taylor [this message]
2005-08-26 12:07 ` bug? Eljay Love-Jensen
  -- strict thread matches above, loose matches on Subject: below --
2007-10-21 14:27 bug? skaller
2007-10-22 11:19 ` bug? John Love-Jensen
2007-10-23  8:04   ` bug? skaller
2003-09-20  7:45 Bug? Brian
2002-02-06  4:34 Bug???? kabir.patel
2001-06-15 15:57 bug? Ben Kohlen
2001-06-15 16:38 ` bug? David Berthelot
2001-06-15 18:59 ` bug? Alexandre Oliva
2001-06-17  2:55 ` bug? Ingo Krabbe
2001-06-18 10:06   ` bug? David Berthelot
2001-06-18 11:46     ` bug? Ingo Krabbe
2001-06-18 23:05       ` bug? Alexandre Oliva
2001-06-18 23:58         ` bug? Ingo Krabbe
2001-06-19  0:31           ` bug? Alexandre Oliva
2001-06-19  5:55             ` bug? Ingo Krabbe
2001-06-20  7:57               ` bug? Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e393d08050825180662798dbc@mail.gmail.com \
    --to=corey.taylor@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=sokolhacker@mail.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).