is it a bug of "cppunitlite"?

Discussion in 'C++' started by LewGun@gmail.com, Sep 12, 2008.

  1. Guest

    Hi all:
    Today, i read the source code of "cppunitlite", a obscure
    problem come from the funciton: (the function reside in the
    simplestring.cpp)

    SimpleString SimpleString::eek:perator= (const SimpleString&
    other)
    {
    delete buffer; //???
    buffer = new char [other.size() + 1];
    strcpy(buffer, other.buffer);
    return *this;
    }

    "buffer" is a instance of " char * ", so i want to know,the
    statment "delete buffer", is it a ill statment? if not, why?
     
    , Sep 12, 2008
    #1
    1. Advertising

  2. James Kanze Guest

    On Sep 12, 8:37 am, "" <> wrote:
    > Today, i read the source code of "cppunitlite", a obscure
    > problem come from the funciton: (the function reside in the
    > simplestring.cpp)


    > SimpleString SimpleString::eek:perator= (const SimpleString&
    > other)
    > {
    > delete buffer; //???
    > buffer = new char [other.size() + 1];
    > strcpy(buffer, other.buffer);
    > return *this;
    > }


    > "buffer" is a instance of " char * ", so i want to know,the
    > statment "delete buffer", is it a ill statment? if not, why?


    It depends on how the memory for buffer was allocated, but a
    priori, it's undefined behavior here, since the memory seems to
    have been allocated by a new[].

    As assignment operators go, this one is broken anyway. I don't
    know where the code comes from, but the author obviously isn't
    competent to write C++.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 12, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    Re: BUG? OR NOT A BUG?

    John, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    555
  2. RedEye
    Replies:
    2
    Views:
    588
    Jason Kester
    Dec 13, 2005
  3. Michel Joly de Lotbiniere

    Bug Parade Bug 4953793

    Michel Joly de Lotbiniere, Nov 30, 2003, in forum: Java
    Replies:
    4
    Views:
    649
    Michel
    Dec 2, 2003
  4. DarkSpy
    Replies:
    4
    Views:
    893
    tom_usenet
    Jun 27, 2003
  5. Steve Holden
    Replies:
    1
    Views:
    402
    Behrang Dadsetan
    Jul 2, 2003
Loading...

Share This Page