Skip to content

Commit

Permalink
Merge pull request #706 from Wargus/warning_fix
Browse files Browse the repository at this point in the history
Warning fix
  • Loading branch information
Jarod42 authored Aug 1, 2024
2 parents 1d516c1 + 887389a commit 2d766d1
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 101 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#
#

cmake_minimum_required(VERSION 3.5)
cmake_policy(VERSION 3.10..3.20.2)
cmake_minimum_required(VERSION 3.25)

#########################
# Version configuration #
Expand Down Expand Up @@ -55,7 +54,7 @@ option(DOWNLOAD_FREEPATS OFF)
project(stratagus)

if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/third-party/CMakeLists.txt")
add_subdirectory(third-party)
add_subdirectory(third-party EXCLUDE_FROM_ALL SYSTEM)
else()
message(WARNING "Third-party directory not populated, cannot vendor any dependencies.")
endif()
Expand Down Expand Up @@ -84,10 +83,11 @@ endif()

include_directories(
src/include
src/third_party/
${CMAKE_CURRENT_BINARY_DIR}
)

include_directories(SYSTEM src/third_party/)

set(action_SRCS
src/action/action_attack.cpp
src/action/action_board.cpp
Expand Down Expand Up @@ -794,7 +794,7 @@ endif()

if(WITH_STACKTRACE AND STACKTRACE_FOUND)
add_definitions(-DUSE_STACKTRACE ${STACKTRACE_DEFINITIONS})
include_directories(${STACKTRACE_PROJECT_DIR})
include_directories(SYSTEM ${STACKTRACE_PROJECT_DIR})
set(stratagus_LIBS ${stratagus_LIBS} ${STACKTRACE_LIBRARY})
endif()

Expand Down Expand Up @@ -855,7 +855,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Profile")
find_package(coz-profiler)
if(COZ-PROFILER_FOUND)
add_definitions(-DHAVE_COZ_PROFILER)
include_directories(${COZ_INCLUDE_DIRS})
include_directories(SYSTEM ${COZ_INCLUDE_DIRS})
set(stratagus_LIBS ${stratagus_LIBS} ${COZ_LIBRARIES} -ldl)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -g -ggdb")
Expand Down Expand Up @@ -1116,7 +1116,7 @@ endif ()
target_link_libraries(stratagus_lib PUBLIC ${stratagus_LIBS} ${CMAKE_DL_LIBS} guichan_lib)
target_link_libraries(stratagus PUBLIC stratagus_lib)

target_include_directories(stratagus_lib PRIVATE third-party/mdns third-party/spiritless_po/include)
target_include_directories(stratagus_lib SYSTEM PRIVATE third-party/mdns third-party/spiritless_po/include)

if(WITH_OPENMP AND OpenMP_CXX_FOUND)
add_definitions(-DUSE_OPENMP)
Expand Down
53 changes: 29 additions & 24 deletions src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,8 @@ static void DrawPlayers()
Video.DrawRectangle(ColorGreen, x + 1, y + 1, getPlayerButtonSize() - 1, getPlayerButtonSize() - 1);
}

char buf[256];
sprintf(buf, "%d", i + 1);
CLabel label(GetGameFont());
label.DrawCentered(x + getPlayerButtonSize() / 2, y + 3, buf);
label.DrawCentered(x + getPlayerButtonSize() / 2, y + 3, std::to_string(i + 1));

return true;
});
Expand Down Expand Up @@ -986,23 +984,26 @@ static void DrawEditorInfo()
// Flags info
//
const unsigned flag = mf.getFlag();
sprintf(buf, "elev:(%u) value:(0x%02X) | flags:(0x%04X)>[%c%c%c%c%c%c%c%c%c%c%c%c%c%c]",
mf.getElevation(),
mf.Value, flag,
flag & MapFieldOpaque ? 'o' : '-',
flag & MapFieldUnpassable ? 'u' : '-',
flag & MapFieldNoBuilding ? 'n' : '-',
flag & MapFieldHuman ? 'h' : '-',
flag & MapFieldWall ? 'w' : '-',
flag & MapFieldRocks ? 'r' : '-',
flag & MapFieldForest ? 'f' : '-',
flag & MapFieldLandAllowed ? 'L' : '-',
flag & MapFieldCoastAllowed ? 'C' : '-',
flag & MapFieldWaterAllowed ? 'W' : '-',
flag & MapFieldLandUnit ? 'l' : '-',
flag & MapFieldAirUnit ? 'a' : '-',
flag & MapFieldSeaUnit ? 's' : '-',
flag & MapFieldBuilding ? 'b' : '-');
snprintf(buf,
sizeof(buf),
"elev:(%u) value:(0x%02X) | flags:(0x%04X)>[%c%c%c%c%c%c%c%c%c%c%c%c%c%c]",
mf.getElevation(),
mf.Value,
flag,
flag & MapFieldOpaque ? 'o' : '-',
flag & MapFieldUnpassable ? 'u' : '-',
flag & MapFieldNoBuilding ? 'n' : '-',
flag & MapFieldHuman ? 'h' : '-',
flag & MapFieldWall ? 'w' : '-',
flag & MapFieldRocks ? 'r' : '-',
flag & MapFieldForest ? 'f' : '-',
flag & MapFieldLandAllowed ? 'L' : '-',
flag & MapFieldCoastAllowed ? 'C' : '-',
flag & MapFieldWaterAllowed ? 'W' : '-',
flag & MapFieldLandUnit ? 'l' : '-',
flag & MapFieldAirUnit ? 'a' : '-',
flag & MapFieldSeaUnit ? 's' : '-',
flag & MapFieldBuilding ? 'b' : '-');
CLabel(GetGameFont()).Draw(UI.StatusLine.TextX, UI.StatusLine.TextY - GetGameFont().getHeight() * 2, buf);

// Tile info
Expand All @@ -1027,11 +1028,15 @@ static void ShowUnitInfo(const CUnit &unit)
{
char buf[256];

int n = sprintf(buf, _("#%d '%s' Player:#%d %s"), UnitNumber(unit),
unit.Type->Name.c_str(), unit.Player->Index + 1,
unit.Active ? "active" : "passive");
int n = snprintf(buf,
sizeof(buf),
_("#%d '%s' Player:#%d %s"),
UnitNumber(unit),
unit.Type->Name.c_str(),
unit.Player->Index + 1,
unit.Active ? "active" : "passive");
if (unit.Type->GivesResource) {
sprintf(buf + n, _(" Amount %d"), unit.ResourcesHeld);
snprintf(buf + n, sizeof(buf) - n, _(" Amount %d"), unit.ResourcesHeld);
}
UI.StatusLine.Set(buf);
}
Expand Down
7 changes: 7 additions & 0 deletions src/include/stratagus.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,16 @@ extern void AbortAt(const char *file, int line, const char *funcName, const char
template <typename... Ts>
std::string Format(const char *format, Ts... args)
{
#ifndef _MSC_VER
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wformat-security"
#endif
const auto len = snprintf(nullptr, 0, format, args...);
std::string res(len, '\0');
snprintf(res.data(), res.size(), format, args...);
#ifndef _MSC_VER
# pragma GCC diagnostic pop
#endif
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/include/ui/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CPopupContentTypeButtonInfo : public CPopupContentType
int GetWidth(const ButtonAction &button, int *Costs) const override;
int GetHeight(const ButtonAction &button, int *Costs) const override;

virtual void Parse(lua_State *l);
void Parse(lua_State *l) override;

private:
EPopupButtonInfo InfoType = EPopupButtonInfo::Hint; /// Type of information to show.
Expand Down
Loading

0 comments on commit 2d766d1

Please sign in to comment.