bugGNU gettext - Bugs: bug #33102, autosprintf needs an operator=

 
 

You are not allowed to post comments on this tracker with your current authentification level.

bug #33102: autosprintf needs an operator=

Submitted by:  None
Submitted on:  Sat Apr 16 17:41:21 2011  
 
Category: Programmer interfaceSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: Miguel Ángel Arruga Vivas <m1gu3l>
Open/Closed: Closed

Tue Mar 5 23:39:22 2013, comment #3:

Miguel's patch pushed.

Daiki Ueno <ueno>
Project Administrator
Fri Mar 1 20:10:27 2013, comment #2:

It can be tested at https://github.com/644rosen/gettext_gtkbuilder_support.git in the branch libasprintf and in master

Miguel Ángel Arruga Vivas <m1gu3l>
Project MemberIn charge of this item.
Tue Jan 29 18:02:28 2013, comment #1:

This is a real bug.
You can get more info at http://www.cplusplus.com/articles/y8hv0pDG/ or http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html

The default copy constructor is the same as struct copy in C, so the same pointer is "free"d twice in the example code. Also a pointer to the heap is lost, so there is a memory leak.

With C++11, the keyword delete can be used to forbid copy with '=', or also the operator can be declared private for C++98 compatibility. This will forbid autosprintf assignation:

Error: Compiler error at
x = y;
^^^^

The other way (it is really hard the final implementation differs too much from the patch) allows copy by '=', that also may be wanted at some scenarios.

x = y; // The pointer y->str is not copied to x->str
// Only the contents of y->str are copied to a newly allocated x->str

Miguel Ángel Arruga Vivas <m1gu3l>
Project MemberIn charge of this item.
Sat Apr 16 17:41:21 2011, original submission:

The C++ class autosprintf has a non-trivial destructor and copy constructor, and so by the Rule of Three it also needs an assignment operator. Without this, the following code fragment currently causes a double free when the second object destructs.

gnu::autosprintf x("hi");
gnu::autosprintf y("hello");
x = y;

Attached a straightforward implementation. Valgrind is happy. Not entirely sure I got the ChangeLog format right though.

Anonymous

 

Attached Files
file #23262:  libasprintf-add-assignment-operator-to-autosprintf.patch added by None (2kB - text/x-patch - libasprintf: add assignment operator to autosprintf)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by haible (Updated the item)
  • -unavailable- added by ueno (Posted a comment)
  • -unavailable- added by m1gu3l (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun Nov 27 01:10:15 2016haibleCategoryNone=>Programmer interface
    Tue Mar 5 23:39:22 2013uenoStatusReady For Test=>Fixed
      Open/ClosedOpen=>Closed
    Fri Mar 1 20:10:27 2013m1gu3lStatusIn Progress=>Ready For Test
    Thu Feb 28 10:00:57 2013m1gu3lStatusNone=>In Progress
      Assigned toNone=>m1gu3l
    Sat Apr 16 17:41:21 2011NoneAttached File-=>Added libasprintf-add-assignment-operator-to-autosprintf.patch, #23262

    Back to the top


    Powered by Savane 3.1-cleanup