Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Segfault on std::map creation?
Forum Update on Monday, May 27th 2025

Segfault on std::map creation?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 623 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • adalovegirlsA Offline
    adalovegirlsA Offline
    adalovegirls
    wrote on last edited by
    #1

    In the following code, I get a segfault at the creation of the first pair. The weird thing is, the exact same code works when compiled with the latest standalone MinGW64, and this isn't my code, so I have no idea what the problem is. I'm using the latest Qt5.

    assembler.cpp (link goes to line in GitHub repo)

    // opcodes/byte codes functions mapping table
    typedef uint16_t (*callback)(t_token, Parser*);
    std::map<std::string, callback> opcodes_map;
    
    Assembler::Assembler()
    {
        opcodes_map["JP"]   = &jumpOrCall;
    }
    

    Is this a bug/missing feature in Qt's built-in compiler, or?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @adalovegirls said in Segfault on std::map creation?:

      Qt's built-in compiler

      Qt has no compiler... so what's the relation to Qt here?
      Use a debugger and see where it exactly crashes

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      adalovegirlsA 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @adalovegirls said in Segfault on std::map creation?:

        Qt's built-in compiler

        Qt has no compiler... so what's the relation to Qt here?
        Use a debugger and see where it exactly crashes

        adalovegirlsA Offline
        adalovegirlsA Offline
        adalovegirls
        wrote on last edited by
        #3

        @Christian-Ehrlicher I'm not sure what you mean. Qt5 ships with a built-in MinGW compiler.

        Here's the debug trace:

        1  libstdc++-6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       0x6fcfe12a 
        2  std::_Rb_tree_iterator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>::operator--                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       stl_tree.h    302  0x4323cb   
        3  std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_get_insert_unique_pos                                                                                                                                                                                                                                                                                          stl_tree.h    2063 0x436dac   
        4  std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_get_insert_hint_unique_pos                                                                                                                                                                                                                                                                                     stl_tree.h    2160 0x436f04   
        5  std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<std::string&&>, std::tuple<>>(std::_Rb_tree_const_iterator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::piecewise_construct_t const&, std::tuple<std::string&&>&&, std::tuple<>&&) stl_tree.h    2418 0x436c23   
        6  std::map<std::string, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>::operator[]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      stl_map.h     518  0x432eec   
        7  Assembler::Assembler                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      assembler.cpp 32   0x402d41   
        8  __static_initialization_and_destruction_0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 debugger.cpp  36   0x40ff79   
        9  _GLOBAL__sub_I_disassembly                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                debugger.cpp  391  0x40ffbb   
        10 __do_global_ctors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x41d1b2   
        11 __tmainCRTStartup                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x40139a   
        12 WinMainCRTStartup                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x4014cb   
        

        The line in 7 that the trace refers to is:

            opcodes_map["JP"]   = &jumpOrCall;
        

        After that I have no idea what's happening because STL headers are way too complicated for me to understand as a beginner...

        jsulmJ 1 Reply Last reply
        0
        • adalovegirlsA adalovegirls

          @Christian-Ehrlicher I'm not sure what you mean. Qt5 ships with a built-in MinGW compiler.

          Here's the debug trace:

          1  libstdc++-6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       0x6fcfe12a 
          2  std::_Rb_tree_iterator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>::operator--                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       stl_tree.h    302  0x4323cb   
          3  std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_get_insert_unique_pos                                                                                                                                                                                                                                                                                          stl_tree.h    2063 0x436dac   
          4  std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_get_insert_hint_unique_pos                                                                                                                                                                                                                                                                                     stl_tree.h    2160 0x436f04   
          5  std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<std::string&&>, std::tuple<>>(std::_Rb_tree_const_iterator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::piecewise_construct_t const&, std::tuple<std::string&&>&&, std::tuple<>&&) stl_tree.h    2418 0x436c23   
          6  std::map<std::string, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>::operator[]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      stl_map.h     518  0x432eec   
          7  Assembler::Assembler                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      assembler.cpp 32   0x402d41   
          8  __static_initialization_and_destruction_0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 debugger.cpp  36   0x40ff79   
          9  _GLOBAL__sub_I_disassembly                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                debugger.cpp  391  0x40ffbb   
          10 __do_global_ctors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x41d1b2   
          11 __tmainCRTStartup                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x40139a   
          12 WinMainCRTStartup                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x4014cb   
          

          The line in 7 that the trace refers to is:

              opcodes_map["JP"]   = &jumpOrCall;
          

          After that I have no idea what's happening because STL headers are way too complicated for me to understand as a beginner...

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @adalovegirls said in Segfault on std::map creation?:

          Qt5 ships with a built-in MinGW compiler

          Qt is a C++ framework and not a compiler. Yes, you can install MinGW when installing Qt, but this does not mean that it is "built-in" in Qt.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #5

            @adalovegirls said in Segfault on std::map creation?:

            jumpOrCall

            Since this seems to be a global static somehwere I would guess jumpOrCall is not yet initialized. Don't use global statics!

            Qt5 ships with a built-in MinGW compiler.

            No, there is no Qt-build-in compiler. There is only a compiler which is used to compile Qt programs, nothing more.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Why did you delete the topic?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved