• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Dolphin Site › Dolphin Patches (Archive) v
1 2 3 4 5 ... 7 Next »

[PATCH] NetPlayDiag::FindGame(): do not return reference to temporary
View New Posts | View Today's Posts

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
[PATCH] NetPlayDiag::FindGame(): do not return reference to temporary
08-12-2013, 09:48 PM
#1
devm33
Unregistered
 
NetPlayDiag::FindGame() returns const reference to std:Confusedtring.
If game path isn't found, it returns "".
Because of implicit conversion, it results:
return std:Confusedtring("");
Using a reference to a destroyed object causes undefined behavior.
This commit fixes it by returning copied std:Confusedtring objects.

---
diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp
index 1c8f054..e4bc377 100644
--- a/Source/Core/DolphinWX/Src/NetWindow.cpp
+++ b/Source/Core/DolphinWX/Src/NetWindow.cpp
@@ -409,7 +409,7 @@ void NetPlayDiag::GetNetSettings(NetSettings &settings)
settings.m_Controllers = SConfig::GetInstance().m_SIDevice[i];
}

-const std:Confusedtring& NetPlayDiag::FindGame()
+std:Confusedtring NetPlayDiag::FindGame()
{
// find path for selected game, sloppy..
for (u32 i = 0 ; auto game = m_game_list->GetISO(i); ++i)
diff --git a/Source/Core/DolphinWX/Src/NetWindow.h b/Source/Core/DolphinWX/Src/NetWindow.h
index 543c164..e798033 100644
--- a/Source/Core/DolphinWX/Src/NetWindow.h
+++ b/Source/Core/DolphinWX/Src/NetWindow.h
@@ -92,7 +92,7 @@ private:
void OnAdjustBuffer(wxCommandEvent& event);
void OnConfigPads(wxCommandEvent& event);
void GetNetSettings(NetSettings &settings);
- const std:Confusedtring& FindGame();
+ std:Confusedtring FindGame();

wxListBox* m_player_lbox;
wxTextCtrl* m_chat_text;
--

#
# I'm new and not familiar with dolphin-emu
# I concern about copying std:Confusedtring objects each time FindGame() is called
# may affect the performance of dolphin.
#
[/i]
08-14-2013, 05:55 AM
#2
jchadwick
Unregistered
 
Indeed, this is invalid C++ code. I just landed revision a791733c27fa with the fix. Performance is certainly not going to be a problem, so no need to worry.

By the way, these forums mangle whitespace something nasty. If you want patches to be applied directly from your diff, then I recommend you use git format-patch (you appear to be doing this correctly already) and upload the patch to somewhere else. (A pastebin will probably work, though I actually recommend something that hosts binary files- that way, we can be completely sure the file is byte-for-byte what it was when git produced it.)
08-14-2013, 06:44 AM
#3
delroth Offline
Making the world a better place through reverse engineered DSP firmwares
**********
Developers (Some Administrators and Super Moderators)
Posts: 1,354
Threads: 63
Joined: Aug 2011
Or use [ code ]

Code:
Foo
    Bar
Pierre "delroth" Bourdon - @delroth_ - Blog

<@neobrain> that looks sophisticated enough to not be a totally dumb thing to do
Website Find
08-16-2013, 12:00 AM
#4
devm33
Unregistered
 
First, thank you for applying the patch to master.

>> By the way, these forums mangle whitespace something nasty
Sorry, I missed it.

>> Or use [ code ]
Sure. I will use this next time. Thank you.
« Next Oldest | Next Newest »


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 1 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode