if(s_SelectionPopupContext.m_Entries.size() == 1)
{
s_SelectionPopupContext.m_pSelection = &*s_SelectionPopupContext.m_Entries.begin();
}
Does this result in undefined behaviour? m_Entries
is a std::set<std::string>
. I'm want to get a pointer to the first element. As you can see I ensure that there is exactly one element in the set and the set will not be modified in the meantime, so taking a pointer should be fine. But if I dereference the iterator with *
, doesn't this create a temporary copy of the entry that I would then take the address of with &
? In that case the address would point to a temporary object that is no longer valid outside the scope of this if-block.
I could also do the following, which should definitely work, as it uses a reference to the string, albeit it looks a bit odd:
if(s_SelectionPopupContext.m_Entries.size() == 1)
{
for(const auto &Entry : s_SelectionPopupContext.m_Entries)
{
s_SelectionPopupContext.m_pSelection = &Entry;
}
}
std::string
, so can I even do that?std::string&
std::string *
, because I also need it to be a nullptr
when it's empty
Core was generated by
./DDRace64-Server_sql -f servers/8308.cfg'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f990902b0a4 in ?? () from /lib/x86_64-linux-gnu/libcurl.so.4
[Current thread is 1 (Thread 0x7f99060c0700 (LWP 1145086))]
(gdb) bt
#0 0x00007f990902b0a4 in ?? () from /lib/x86_64-linux-gnu/libcurl.so.4
#1 0x00007f990902b9b2 in ?? () from /lib/x86_64-linux-gnu/libcurl.so.4
#2 0x00007f990903de76 in ?? () from /lib....exe
, it should also work there i guess, but not tested.
info symbol 0x...
addr2line -e DDNet.exe 000000000051576F
/home/deen/isos/ddnet/ddnet-source/src/game/editor/layer_tiles.cpp:54
CTile CLayerTiles::GetTile(int x, int y)
{
return m_pTiles[y * m_Width + x];
}
addr2line -e DDNet.exe 00000000005193DB
/home/deen/isos/ddnet/ddnet-source/src/game/editor/layer_tiles.cpp:441
addr2line -e DDNet.exe 000000000050B3B5
/home/deen/isos/ddnet/ddnet-source/src/game/editor/editor.cpp:2632
(edited)NASA is the best and SpaceX is the worst or well Elon Musk is the worst
well at least dont put words in my mouthNASA is the best and SpaceX is the worst or well Elon Musk is the worst
well at least dont put words in my mouth