A joke
Giorgos Keramidas
keramida at ceid.upatras.gr
Thu Jun 1 07:09:46 PDT 2006
On 2006-06-01 10:45, Rico <coolzone at 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");
:)
More information about the freebsd-chat
mailing list