bugDDD - Bugs: bug #51281, WhenReadyInfo::WhenReadyInfo() :...


bug #51281: WhenReadyInfo::WhenReadyInfo() : wrong use of memcpy()

Submitted by:  Zdenek Sojka <zsojka>
Submitted on:  Tue 20 Jun 2017 09:15:26 PM UTC  
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Release:  3.3.12-rc2

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Wed 21 Jun 2017 09:10:09 AM UTC, comment #2: 

cbs.event is written to just on the very next line, so if the intention of the memcpy() is to write cbs.event, it can be removed altogether.

Zdenek Sojka <zsojka>
Wed 21 Jun 2017 07:55:00 AM UTC, comment #1: 

The compiler warning is correct but the fix should just require the address-of operator (&) on the first parameter cbs.event.

Ian Kirkham <expl_squirrel>
Project Member
Tue 20 Jun 2017 09:15:26 PM UTC, original submission:  

When compiling DDD with a recent gcc (5.4.0 in my case), the following warning is given:

ddd.C: In constructor 'WhenReadyInfo::WhenReadyInfo(const MString&, XtCallbackProc, XtPointer, const XmPushButtonCallbackStruct&)':
ddd.C:5825:39: warning: argument to 'sizeof' in 'void* memcpy(void*, const void*, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
      memcpy(cbs.event, c.event, sizeof(cbs.event));

The warning seems to be valid, since the memcpy() parameters are most likely the same (dst == src), and the size is size_of_pointer.

event is unitialized (its default constructor is used; if applicable)

This patch might trigger the originally intended behavior:

+++ ddd/ddd.C   2017-06-20 23:03:48.946830931 +0200
@@ -5822,7 +5822,7 @@
-           memcpy(cbs.event, c.event, sizeof(cbs.event));
+           memcpy(&event, c.event, sizeof(event));
            cbs.event = &event;

Zdenek Sojka <zsojka>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by expl_squirrel (Posted a comment)
  • -email is unavailable- added by zsojka (Submitted the item)

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

    Only logged-in users can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.7