Date: Thu, 1 Jun 2006 17:11:44 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Rico <coolzone@io.dk> Cc: freebsd-chat@freebsd.org Subject: Re: A joke Message-ID: <20060601141144.GC6057@gothmog.pc> In-Reply-To: <447EA92E.8070500@io.dk> References: <447EA92E.8070500@io.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-06-01 10:45, Rico <coolzone@io.dk> wrote: > Seasoned pro > ------------ I really don't think so! This seasoned ``pro'' has a buffer overflow in his class :P Not to mention the other C++ bug in there too... > #include <stream.h> > > const int MAXLEN = 80; > class outstring; > class outstring { > private: > int size; > char str[MAXLEN]; > public: > outstring() { size=0; } > ~outstring() {size=0;} > void print(); > void assign(char *chrs); > }; > > void outstring::print() { > int i; > for (i=0 ; i< size ; i++) > cout << str[i]; > cout << "\n"; > } > > void outstring::assign(char *chrs) { > int i; > for (i=0; chrs[i] != '\0';i++) > str[i] = chrs[i]; > size=i; > } > > main (int argc, char **argv) { > outstring string; > string.assign("Hello World!"); > string.print(); > } outstring.assign("This line is too long for the absurd limit " "of `MAXLINE' characters and will probably result in something " "weird happening; anything is possible in the land of " "undefined behavior, yay!\n"); :)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060601141144.GC6057>