mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Merge pull request #3746 from IvanSavenko/fix_undefined_behavior
Fix discovered undefined behavior cases
This commit is contained in:
commit
0bd1c3c95d
@ -393,6 +393,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR NOT WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=array-bounds") # false positives in boost::multiarray during release build, keep as warning-only
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT WIN32)
|
||||
# For gcc 14+ we can use -fhardened instead
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection=full")
|
||||
endif()
|
||||
|
||||
# Fix string inspection with lldb
|
||||
# https://stackoverflow.com/questions/58578615/cannot-inspect-a-stdstring-variable-in-lldb
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
|
6
Global.h
6
Global.h
@ -104,12 +104,6 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Enable additional debug checks from glibc / libstdc++ when building with enabled assertions
|
||||
// Since these defines must be declared BEFORE including glibc header we can not check for __GLIBCXX__ macro to detect that glibc is in use
|
||||
# define _GLIBCXX_ASSERTIONS
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <any>
|
||||
#include <array>
|
||||
|
@ -322,6 +322,13 @@ void CSoundHandler::setCallback(int channel, std::function<void()> function)
|
||||
iter->second.push_back(function);
|
||||
}
|
||||
|
||||
void CSoundHandler::resetCallback(int channel)
|
||||
{
|
||||
boost::mutex::scoped_lock lockGuard(mutexCallbacks);
|
||||
|
||||
callbacks.erase(channel);
|
||||
}
|
||||
|
||||
void CSoundHandler::soundFinishedCallback(int channel)
|
||||
{
|
||||
boost::mutex::scoped_lock lockGuard(mutexCallbacks);
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
void stopSound(int handler);
|
||||
|
||||
void setCallback(int channel, std::function<void()> function);
|
||||
void resetCallback(int channel);
|
||||
void soundFinishedCallback(int channel);
|
||||
|
||||
int ambientGetRange() const;
|
||||
|
@ -213,12 +213,21 @@ void EventDispatcher::handleLeftButtonClick(const Point & position, int toleranc
|
||||
if( i->receiveEvent(position, AEventsReceiver::LCLICK) || i == nearestElement)
|
||||
{
|
||||
if(isPressed)
|
||||
{
|
||||
i->mouseClickedState = isPressed;
|
||||
i->clickPressed(position, lastActivated);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i->mouseClickedState)
|
||||
{
|
||||
i->mouseClickedState = isPressed;
|
||||
i->clickReleased(position, lastActivated);
|
||||
}
|
||||
else
|
||||
i->mouseClickedState = isPressed;
|
||||
}
|
||||
|
||||
if (i->mouseClickedState && !isPressed)
|
||||
i->clickReleased(position, lastActivated);
|
||||
|
||||
i->mouseClickedState = isPressed;
|
||||
lastActivated = false;
|
||||
}
|
||||
else
|
||||
|
@ -155,12 +155,12 @@ SelectionTab::SelectionTab(ESelectionScreen Type)
|
||||
OBJ_CONSTRUCTION;
|
||||
|
||||
generalSortingBy = getSortBySelectionScreen(tabType);
|
||||
sortingBy = _format;
|
||||
|
||||
bool enableUiEnhancements = settings["general"]["enableUiEnhancements"].Bool();
|
||||
|
||||
if(tabType != ESelectionScreen::campaignList)
|
||||
{
|
||||
sortingBy = _format;
|
||||
background = std::make_shared<CPicture>(ImagePath::builtin("SCSELBCK.bmp"), 0, 6);
|
||||
pos = background->pos;
|
||||
inputName = std::make_shared<CTextInput>(inputNameRect, Point(-32, -25), ImagePath::builtin("GSSTRIP.bmp"), 0);
|
||||
|
@ -74,6 +74,7 @@ void CPrologEpilogVideo::show(Canvas & to)
|
||||
void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
|
||||
{
|
||||
close();
|
||||
CCS->soundh->resetCallback(voiceSoundHandle); // reset callback to avoid memory corruption since 'this' will be destroyed
|
||||
CCS->soundh->stopSound(voiceSoundHandle);
|
||||
CCS->soundh->stopSound(videoSoundHandle);
|
||||
if(exitCb)
|
||||
|
@ -71,7 +71,7 @@ using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
|
||||
class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver
|
||||
{
|
||||
public:
|
||||
bool human;
|
||||
bool human = false;
|
||||
PlayerColor playerID;
|
||||
std::string dllName;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user