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


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

bug #33102: autosprintf needs an operator=

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

Tue 05 Mar 2013 11:39:22 PM UTC, comment #3:

Miguel's patch pushed.

Daiki Ueno <ueno>
Project Administrator
Fri 01 Mar 2013 08:10:27 PM UTC, 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 29 Jan 2013 06:02:28 PM UTC, 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 16 Apr 2011 05:41:21 PM UTC, 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.



Attached Files
file #23262:  libasprintf-add-assignment-operator-to-autosprintf.patch added by None (2KiB - 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 27 Nov 2016 01:10:15 AM UTChaibleCategoryNone=>Programmer interface
    Tue 05 Mar 2013 11:39:22 PM UTCuenoStatusReady For Test=>Fixed
    Fri 01 Mar 2013 08:10:27 PM UTCm1gu3lStatusIn Progress=>Ready For Test
    Thu 28 Feb 2013 10:00:57 AM UTCm1gu3lStatusNone=>In Progress
      Assigned toNone=>m1gu3l
    Sat 16 Apr 2011 05:41:21 PM UTCNoneAttached File-=>Added libasprintf-add-assignment-operator-to-autosprintf.patch, #23262

    Back to the top

    Powered by Savane 3.1-cleanup1