MySQL Bug Report WTF



  • While looking for something else, I ran across this:
    http://bugs.mysql.com/bug.php?id=12194

    A short summary:

    Someone noticed valgrind was reporting an overlapping memcpy.

    The warning clearly shows the problem being memcpy(Pointer, EquivalentPointer, 1);

     The solution? Of course! Use memmove() instead, since it allows overlapping pointers. 

     

    WTF's include:

    Why are you copying the same data on top of itself in the first place?

    Why are you modifying your code to suppress what (by chance) is a valid warning?

    Even if you knew it to not be valid, why modify it in that way anyway, since memcpy(TheSamePointer, TheSamePointer, Anything); can't ever effect anything anyway? (yeah, they overlap.. but oh no! you might copy parts of the destination (which is the source) on to the destination, instead of the source (which is the destination) on to the destination!)

     
    Valgrind showing things in somebody else's library is always annoying, yeah. But wtf? 



  • @skztr said:

    The solution? Of course! Use memmove() instead, since it allows overlapping pointers. 

    Bzzzt.  The solution?  Use Postgres! 

     

    WTF's include:

    You forgot one: They aren't using Postgres.

     Why anyone uses MySQL for new applications these days is beyond me...
     



  • @jazzcat said:

    Postgres!

    Speaking as a postgres weenie?  Nobody benefits from this kind of zealotry.  Cut it the hell out. 



  • @Angstrom said:

    Speaking as a postgres weenie?  Nobody benefits from this kind of zealotry.  Cut it the hell out. 

    As a postgres weenie I say use SQL Server or DB2 or Oracle (OK maybe not Oracle). Just use anything except MySQL.


    And yes I have used MySQL for production stuff where it was pre-existing. It just does not cut it, sorry.

     

    -Andrew

     



  • I guess I should clarify:

    "The solution" == "The solution used"

     Changing memcpy(TheSamePointer, TheSamePointer, 1); to memmove(TheSamePointer, TheSamePointer, 1); is stupid no matter what db you're using.
     



  • I think you're mis-reading the bug. "Overlapping" doesn't mean the two memory blocks have the same start/end points, just that they share one or more bytes in common. i.e: Source block goes from 200-300, and Destination goes from 250-350.

    I'll agree that a memcpy with identical source/destinations is a waste (unless you're trying to exercise the hardware somehow), but doing a memmove with non-identical source/destination could be used to defrag the app's allocated memory blocks.
     



  • @jazzcat said:

    Use Postgres! 

    It's Postgre.

    If you're such a fan, learn to spell it.

     



  • @CDarklock said:

    @jazzcat said:

    Use Postgres! 

    It's Postgre.

    If you're such a fan, learn to spell it.

    Is this a troll?

    Sorry, but PostgreSQL's original name was postgres. The name was a play on the Ingres database system.



  • Correctly spelled, it's POSTGRES. You have to shout the name.



  • "Overlapping" doesn't mean they have the same start/end points. I in no way meant to imply that.

    But in this case, you only got the "overlapping" error because every now and then it was trying to copy data on top of itself. Were it merely "overlapping" that might be a separate issue, but here we can clearly see that this is a case of a source and destination column being the same thing. Were they not the same thing, they would not overlap.



  • @skztr said:

    "Overlapping" doesn't mean they have the same start/end points. I in no way meant to imply that.

    But in this case, you only got the "overlapping" error because every now and then it was trying to copy data on top of itself. Were it merely "overlapping" that might be a separate issue, but here we can clearly see that this is a case of a source and destination column being the same thing. Were they not the same thing, they would not overlap.

    Um, no.

    memcpy() is a C function, used for copying memory.  It takes a source pointer, a destination pointer, and a length in bytes.  It has no concept of "database column", and it's perfectly possible for the pointed-to areas to overlap even if the pointers aren't the same, when you consider the length.  It's a fast, dumb copy, which doesn't consider overlap;  for things where there may be overlap, you use memmove.  That's what it's there for.  Hardly a WTF, except in that they didn't use memmove in the first place for something that's not guaranteed to be overlap-free.
     


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.