FrozenSnake's Profile User Rating: -----

Reputation: 123 Stalwart
Active Members
Active Posts:
1,017 (0.38 per day)
30-July 08
Profile Views:
Last Active:
User is offline Nov 04 2015 11:27 AM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Favorite Gaming Platform:
Your Car:
Who Cares
Dream Kudos:

Latest Visitors

Icon   FrozenSnake has not set their status

Posts I've Made

  1. In Topic: Problem with old code that doesn't work anymore!

    Posted 3 Nov 2015

    View PostXupicor, on 03 November 2015 - 06:48 PM, said:

    The code compiles with similar warnings to Jim's here, but it does crash and produces no output using Windows 8 and g++ 5.1.0 compiled as C++14.

    As ndc85430 mentioned, the most immediately obvious problem is possible dereferencing of a null pointer at line 32 after you possibly let it pass through the below condition at line 26:
    if (right != NULL || left != NULL)

    There's also line 42 where you possibly dereference a null pointer.

    None of those are directly responsible though. What happens is - left and right pointers are not initialized when calling one of the Tree constructors. So, basically, new Tree(9, 'a') makes a new tree (...uh, "tree node" actually, I don't see why a Tree and a Node aren't separated in your code, but that's inconsequential here : P) that has left and right with garbage values. The condition at line 26 lets it through and then you dereference an invalid pointer, bam, it all crashes and burns.

    Thanks for going in-depth in why this is happening!
    But wouldn't it crash right away? I check the content of bitString and it ends up with 000 and then crash.
    Why does it decide to crash when pushing the forth value? I might be asking a stupid question, it is late.

    Anyway I tried this now
    Tree::Tree(int w, char c_) : weight(w), c(c_) { left = NULL; right = NULL; }
    And now it works again!
    I'll rewrite this code later, and add a Node class!
  2. In Topic: Problem with old code that doesn't work anymore!

    Posted 3 Nov 2015

    View Postjimblumberg, on 03 November 2015 - 05:59 PM, said:

    Could it be that two years ago you were using a 32 bit compiler and today you're using a 64 bit compiler?

    As I stated earlier the code ran for me without crashing, this was using a 32 bit compiler. However when using a 64 bit compiler the program crashed on the lines you indicated.


    I checked on C::Bs homepage they use 32bit in the installation I have. I tried compiling both in x86 and x64 in Visual Studio (if I am right in assuming that x64 is 64bit and x86 is "some other" bit). Same problem. :(

    View PostSalem_c, on 03 November 2015 - 06:01 PM, said:

    > Access violation reading location 0xCDCDCDD1."
    0xCD is what the debug version of the runtime library fills memory with when that memory is deleted.

    0xD1 is basically 0xCD + 4.

    In other words, it's likely to be the 2nd member of a structure/class that has been deleted, and this is an example of a 'use after free' error.

    $ g++ -g -Wall bar.cpp -lefence
    bar.cpp: In constructor ‘Tree::Tree(int, Tree*, Tree*)’:
    bar.cpp:17:7: warning: ‘Tree::weight’ will be initialized after [-Wreorder]
    bar.cpp:15:9: warning:   ‘Tree* Tree::left’ [-Wreorder]
    bar.cpp:22:1: warning:   when initialized here [-Wreorder]
    $ gdb -q ./a.out 
    Reading symbols from /home/sc/Documents/a.out...done.
    (gdb) run
    Starting program: /home/sc/Documents/a.out 
    000 : a
    Program received signal SIGSEGV, Segmentation fault.
    0x0000000000400e39 in Tree::printTree (this=0x0, bitString=...) at bar.cpp:26
    26        if (right != NULL || left != NULL)
    (gdb) bt
    #0  0x0000000000400e39 in Tree::printTree (this=0x0, bitString=...) at bar.cpp:26
    #1  0x0000000000400ec7 in Tree::printTree (this=0x605070, bitString=...) at bar.cpp:32
    #2  0x0000000000400e7a in Tree::printTree (this=0x6050e0, bitString=...) at bar.cpp:29
    #3  0x0000000000400e7a in Tree::printTree (this=0x605100, bitString=...) at bar.cpp:29
    #4  0x000000000040118d in main () at bar.cpp:67
    (gdb) print bitString 
    $1 = (std::string &) @0x7fffffffdf70: {static npos = <optimized out>, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, 
        _M_p = 0x605138 "001"}}

    Use your debugger to start looking around for the problem.
    For me, it ended up calling the function with a NULL pointer.

    I'll take a look soon! Need to run to the post office real quick! Thanks for the tip!
  3. In Topic: Problem with old code that doesn't work anymore!

    Posted 3 Nov 2015

    View Postjimblumberg, on 03 November 2015 - 05:01 PM, said:

    Other than having a few warnings when I compile your code, it runs without crashing and produces the following output:
    I tried compiling with Code::Blocks 13.12 (TDM-GCC 4.8.1) and Visual Studio Community 2015. It crashes with both of these ://>

    View Postndc85430, on 03 November 2015 - 04:56 PM, said:

    Are you sure that the condition in the if statement in printTree() is correct? What happens, for example, if right is not null, but left is?

    Also, have you gotten into the habit of using version control yet? If not, you really should.
    The code hasn't been changed in 2 years. It worked 2 years ago, at least well enough to pass the assignment. I use github and bitbucket; this code is taken from my bitbucket.
  4. In Topic: Looking for a good tutorial on ECS

    Posted 25 Apr 2015

    I searched on "Entity Component System tutorial", "Entity Component System tutorial c++", "Entity Component System c++", "ECS c++ tutorial" and such.
    But I mainly ended up on blogs or articles with "ecs is this for me".
  5. In Topic: JSON problem (I think)

    Posted 9 Feb 2015

    I used ObjectOutputStream prior to using JSON without all these problems. It looks a bit different in the files then.
    I have checked out DataOutputStream but I can't figure it out.
    I'll keep digging in it I guess :P and hope for the best.

My Information

Member Title:
En man från Sverige!
31 years old
October 31, 1984
Sweden, Gävle
Full Name:
Kim Wahlman
Years Programming:
Programming Languages:
Php, C++

Contact Information

Website URL:
Website URL  http://


Page 1 of 1
  1. Photo

    Martyn.Rae Icon

    14 Feb 2010 - 04:37
    Davs, hvordan gør det i Sverige?
Page 1 of 1