Thread: Problem with SDL

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    1

    Problem with SDL

    Its causing me memory leaks. In lines 13-40. I have no idea whats causing this so I would like someone to look at it for me.

    Thanks allready in advance.

    http://nopaste.php-q.net/226119

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > char *convert = (char*)malloc(10);
    > delete convert;
    1. Make your mind up as to whether this is C or C++.
    Use malloc + free or new + delete.
    Never mix the two.

    In particular, if you do
    char *convert = new char[10];
    Then you MUST do
    delete [ ] convert; // Yes, the [ ] are important.

    Also, 10 characters is woefully inadequate
    > sprintf(convert, "Damage %d-%d", player_mindamage, player_maxdamage);
    The fixed characters account for 8 chars, and then allowing for the \0, leaves only ONE char for BOTH integers.
    Instant buffer overflow.

    You may as well just declare
    char convert[100];
    and save yourself a whole bunch of memory management problems.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL Performance problem
    By cboard_member in forum Game Programming
    Replies: 8
    Last Post: 04-09-2006, 01:23 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. SDL problem
    By ElastoManiac in forum Game Programming
    Replies: 11
    Last Post: 01-11-2006, 02:45 AM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM