From 3f6d9db4209f384b67503bf1faf06c9aa6026546 Mon Sep 17 00:00:00 2001 From: s1lent Date: Thu, 6 Feb 2020 19:11:07 +0700 Subject: [PATCH] Fixed some compiler warnings Fixed a appversion.sh when the path may contain spaces --- regamedll/CMakeLists.txt | 4 +- regamedll/dlls/client.cpp | 4 +- regamedll/dlls/player.cpp | 2 +- regamedll/dlls/sound.cpp | 22 ++++---- regamedll/game_shared/bot/nav_area.cpp | 14 ++--- regamedll/version/appversion.sh | 76 +++++++++++++------------- 6 files changed, 61 insertions(+), 61 deletions(-) diff --git a/regamedll/CMakeLists.txt b/regamedll/CMakeLists.txt index ff6431d5..c357185b 100644 --- a/regamedll/CMakeLists.txt +++ b/regamedll/CMakeLists.txt @@ -59,7 +59,7 @@ else() endif() if (NOT DEBUG AND USE_STATIC_LIBSTDC) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-gc-sections -Wl,--version-script=${PROJECT_SOURCE_DIR}/../version_script.lds") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-gc-sections -Wl,--version-script=\"${PROJECT_SOURCE_DIR}/../version_script.lds\"") endif() if (USE_STATIC_LIBSTDC) @@ -142,7 +142,7 @@ add_definitions( add_library(regamedll SHARED ${appversion.sh} ${GAMEDLL_SRCS} ${ENGINE_SRCS} ${SHARED_SRCS}) set_property(TARGET regamedll PROPERTY LIBRARY_OUTPUT_NAME cs) -add_custom_target(appversion COMMAND ${PROJECT_SOURCE_DIR}/version/appversion.sh ${PROJECT_SOURCE_DIR} regamedll) +add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/version/appversion.sh" "${PROJECT_SOURCE_DIR}") set_target_properties(regamedll PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON) target_link_libraries(regamedll dl aelf32) add_dependencies(regamedll appversion) diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 159e219d..f20e1885 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -3209,7 +3209,7 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa { if (pPlayer->pev->deadflag != DEAD_NO && pPlayer->m_autoBuyString[0] != '\0') return; - + pPlayer->ClearAutoBuyData(); for (int i = 1; i < CMD_ARGC_(); i++) @@ -3229,7 +3229,7 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa { if (pPlayer->pev->deadflag != DEAD_NO && pPlayer->m_rebuyString) return; - + if (CMD_ARGC_() == 2) { pPlayer->InitRebuyData(parg1); diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 1d75039b..a78afef7 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -6859,7 +6859,7 @@ void CBasePlayer::SendHostageIcons() if (hostagesCount > MAX_HOSTAGE_ICON) hostagesCount = MAX_HOSTAGE_ICON; - char buf[16]; + char buf[18]; Q_snprintf(buf, ARRAYSIZE(buf), "hostage%d", hostagesCount); if (hostagesCount) diff --git a/regamedll/dlls/sound.cpp b/regamedll/dlls/sound.cpp index 57605f7f..baf5353c 100644 --- a/regamedll/dlls/sound.cpp +++ b/regamedll/dlls/sound.cpp @@ -1044,7 +1044,7 @@ int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int fres { char *szgroupname; unsigned char count; - char sznum[8]; + char sznum[12]; if (!fSentencesInit) return -1; @@ -1063,7 +1063,7 @@ int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int fres Q_strcpy(szfound, "!"); Q_strcat(szfound, szgroupname); - Q_sprintf(sznum, "%d", ipick); + Q_snprintf(sznum, sizeof(sznum), "%d", ipick); Q_strcat(szfound, sznum); if (ipick >= count) @@ -1090,7 +1090,7 @@ int USENTENCEG_Pick(int isentenceg, char *szfound) unsigned char *plru; unsigned char i; unsigned char count; - char sznum[8]; + char sznum[12]; unsigned char ipick = 0xFF; BOOL ffound = FALSE; @@ -1121,7 +1121,7 @@ int USENTENCEG_Pick(int isentenceg, char *szfound) { Q_strcpy(szfound, "!"); Q_strcat(szfound, szgroupname); - Q_sprintf(sznum, "%d", ipick); + Q_snprintf(sznum, sizeof(sznum), "%d", ipick); Q_strcat(szfound, sznum); return ipick; @@ -1243,7 +1243,7 @@ int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szgroupname, float v NOXREF void SENTENCEG_Stop(edict_t *entity, int isentenceg, int ipick) { char buffer[64]; - char sznum[8]; + char sznum[12]; if (!fSentencesInit) return; @@ -1251,10 +1251,10 @@ NOXREF void SENTENCEG_Stop(edict_t *entity, int isentenceg, int ipick) if (isentenceg < 0 || ipick < 0) return; - Q_strcpy(buffer, "!"); - Q_strcat(buffer, rgsentenceg[isentenceg].szgroupname); - Q_sprintf(sznum, "%d", ipick); - Q_strcat(buffer, sznum); + Q_strlcpy(buffer, "!"); + Q_strlcat(buffer, rgsentenceg[isentenceg].szgroupname); + Q_snprintf(sznum, sizeof(sznum), "%d", ipick); + Q_strlcat(buffer, sznum); STOP_SOUND(entity, CHAN_VOICE, buffer); } @@ -1387,7 +1387,7 @@ void SENTENCEG_Init() // convert sentence (sample) name to !sentencenum, return !sentencenum int SENTENCEG_Lookup(const char *sample, char *sentencenum) { - char sznum[8]; + char sznum[12]; int i; // this is a sentence name; lookup sentence number @@ -1399,7 +1399,7 @@ int SENTENCEG_Lookup(const char *sample, char *sentencenum) if (sentencenum) { Q_strcpy(sentencenum, "!"); - Q_sprintf(sznum, "%d", i); + Q_snprintf(sznum, sizeof(sznum), "%d", i); Q_strcat(sentencenum, sznum); } diff --git a/regamedll/game_shared/bot/nav_area.cpp b/regamedll/game_shared/bot/nav_area.cpp index 2ad67bb7..f0c9de93 100644 --- a/regamedll/game_shared/bot/nav_area.cpp +++ b/regamedll/game_shared/bot/nav_area.cpp @@ -3806,7 +3806,7 @@ void EditNavAreas(NavEditCmdType cmd) { lastSelectedArea = area; - char buffer[80]; + char buffer[190]; char attrib[80]; char locName[80]; @@ -3829,14 +3829,14 @@ void EditNavAreas(NavEditCmdType cmd) } else { - Q_sprintf(attrib, "%s%s%s%s", + Q_snprintf(attrib, sizeof(attrib), "%s%s%s%s", (area->GetAttributes() & NAV_CROUCH) ? "CROUCH " : "", (area->GetAttributes() & NAV_JUMP) ? "JUMP " : "", (area->GetAttributes() & NAV_PRECISE) ? "PRECISE " : "", (area->GetAttributes() & NAV_NO_JUMP) ? "NO_JUMP " : ""); } - Q_sprintf(buffer, "Area #%d %s %s\n", area->GetID(), locName, attrib); + Q_snprintf(buffer, sizeof(buffer), "Area #%d %s %s\n", area->GetID(), locName, attrib); UTIL_SayTextAll(buffer, pLocalPlayer); // do "place painting" @@ -4018,8 +4018,8 @@ void EditNavAreas(NavEditCmdType cmd) connected += markedArea->GetAdjacentCount(EAST); connected += markedArea->GetAdjacentCount(WEST); - char buffer[80]; - Q_sprintf(buffer, "Marked Area is connected to %d other Areas\n", connected); + char buffer[190]; + Q_snprintf(buffer, sizeof(buffer), "Marked Area is connected to %d other Areas\n", connected); UTIL_SayTextAll(buffer, pLocalPlayer); } break; @@ -4065,8 +4065,8 @@ void EditNavAreas(NavEditCmdType cmd) } } - char buffer[80]; - Q_sprintf(buffer, "Marked Area is connected to %d other Areas - there are %d total unnamed areas\n", connected, totalUnnamedAreas); + char buffer[190]; + Q_snprintf(buffer, sizeof(buffer), "Marked Area is connected to %d other Areas - there are %d total unnamed areas\n", connected, totalUnnamedAreas); UTIL_SayTextAll(buffer, pLocalPlayer); } } diff --git a/regamedll/version/appversion.sh b/regamedll/version/appversion.sh index 35a94cb5..553e3311 100755 --- a/regamedll/version/appversion.sh +++ b/regamedll/version/appversion.sh @@ -2,19 +2,20 @@ init() { - SOURCE_DIR=$1 - VERSION_FILE=$SOURCE_DIR/../gradle.properties - APPVERSION_FILE=$SOURCE_DIR/version/appversion.h + SOURCE_DIR="$@" + GIT_DIR="$SOURCE_DIR/.." + VERSION_FILE="$GIT_DIR/gradle.properties" + APPVERSION_FILE="$SOURCE_DIR/version/appversion.h" if test -z "`git --version`"; then echo "Please install git client" echo "sudo apt-get install git" - exit 0 + exit -1 fi # Read old version - if [ -e $APPVERSION_FILE ]; then - OLD_VERSION=$(cat $APPVERSION_FILE | grep -wi '#define APP_VERSION' | sed -e 's/#define APP_VERSION[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') + if [ -e "$APPVERSION_FILE" ]; then + OLD_VERSION=$(cat "$APPVERSION_FILE" | grep -wi '#define APP_VERSION' | sed -e 's/#define APP_VERSION[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') if [ $? -ne 0 ]; then OLD_VERSION="" else @@ -23,29 +24,28 @@ init() fi fi - - # Get major, minor and maintenance information from version.h - MAJOR=$(sed -nr -e '/majorVersion/ s/.*\= *//p' $VERSION_FILE | tr -d '\n\r') + # Get major, minor and maintenance information from gradle.properties + MAJOR=$(sed -nr -e '/majorVersion/ s/.*\= *//p' "$VERSION_FILE" | tr -d '\n\r') if [ $? -ne 0 -o "$MAJOR" = "" ]; then MAJOR=0 fi - MINOR=$(sed -nr -e '/minorVersion/ s/.*\= *//p' $VERSION_FILE | tr -d '\n\r') + MINOR=$(sed -nr -e '/minorVersion/ s/.*\= *//p' "$VERSION_FILE" | tr -d '\n\r') if [ $? -ne 0 -o "$MINOR" = "" ]; then MINOR=0 fi - MAINTENANCE=$(sed -nr -e '/maintenanceVersion/ s/.*\= *//p' $VERSION_FILE | tr -d '\n\r') + MAINTENANCE=$(sed -nr -e '/maintenanceVersion/ s/.*\= *//p' "$VERSION_FILE" | tr -d '\n\r') if [ $? -ne 0 -o "$MAINTENANCE" = "" ]; then MAINTENANCE=0 fi - BRANCH_NAME=$(git -C $SOURCE_DIR/../ rev-parse --abbrev-ref HEAD) + BRANCH_NAME=$(git -C "$GIT_DIR/" rev-parse --abbrev-ref HEAD) if [ $? -ne 0 -o "$BRANCH_NAME" = "" ]; then BRANCH_NAME=master fi - COMMIT_COUNT=$(git -C $SOURCE_DIR/../ rev-list --count $BRANCH_NAME) + COMMIT_COUNT=$(git -C "$GIT_DIR/" rev-list --count $BRANCH_NAME) if [ $? -ne 0 -o "$COMMIT_COUNT" = "" ]; then COMMIT_COUNT=0 fi @@ -54,17 +54,17 @@ init() # Configure remote url repository # # Get remote name by current branch - BRANCH_REMOTE=$(git -C $SOURCE_DIR/../ config branch.$BRANCH_NAME.remote) + BRANCH_REMOTE=$(git -C "$GIT_DIR/" config branch.$BRANCH_NAME.remote) if [ $? -ne 0 -o "$BRANCH_REMOTE" = "" ]; then BRANCH_REMOTE=origin fi # Get commit id - COMMIT_SHA=$(git -C $SOURCE_DIR/../ rev-parse --verify HEAD) + COMMIT_SHA=$(git -C "$GIT_DIR/" rev-parse --verify HEAD) COMMIT_SHA=${COMMIT_SHA:0:7} # Get remote url - COMMIT_URL=$(git -C $SOURCE_DIR/../ config remote.$BRANCH_REMOTE.url) + COMMIT_URL=$(git -C "$GIT_DIR/" config remote.$BRANCH_REMOTE.url) # Strip prefix 'git@' COMMIT_URL=${COMMIT_URL#git@} @@ -85,7 +85,7 @@ init() # # Detect local modifications # - if [ `git -C $SOURCE_DIR/../ ls-files -m | wc -l` = 0 ]; then + if [ `git -C "$GIT_DIR/" ls-files -m | wc -l` = 0 ]; then MODIFIED= else MODIFIED=+m @@ -109,29 +109,29 @@ update_appversion() # Write appversion.h echo Updating appversion.h, new version is '"'$NEW_VERSION'"', the old one was $OLD_VERSION - echo -e "#ifndef __APPVERSION_H__\r">$APPVERSION_FILE - echo -e "#define __APPVERSION_H__\r">>$APPVERSION_FILE - echo -e "\r">>$APPVERSION_FILE - echo -e "//\r">>$APPVERSION_FILE - echo -e "// This file is generated automatically.\r">>$APPVERSION_FILE - echo -e "// Don't edit it.\r">>$APPVERSION_FILE - echo -e "//\r">>$APPVERSION_FILE - echo -e "\r">>$APPVERSION_FILE - echo -e "// Version defines\r">>$APPVERSION_FILE - echo -e '#define APP_VERSION "'$NEW_VERSION'"\r'>>$APPVERSION_FILE + echo -e "#ifndef __APPVERSION_H__\r">"$APPVERSION_FILE" + echo -e "#define __APPVERSION_H__\r">>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e "//\r">>"$APPVERSION_FILE" + echo -e "// This file is generated automatically.\r">>"$APPVERSION_FILE" + echo -e "// Don't edit it.\r">>"$APPVERSION_FILE" + echo -e "//\r">>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e "// Version defines\r">>"$APPVERSION_FILE" + echo -e '#define APP_VERSION "'$NEW_VERSION'"\r'>>"$APPVERSION_FILE" - echo -e "#define APP_VERSION_C $MAJOR,$MINOR,$MAINTENANCE,$COMMIT_COUNT\r">>$APPVERSION_FILE - echo -e '#define APP_VERSION_STRD "'$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT'"\r'>>$APPVERSION_FILE - echo -e "#define APP_VERSION_FLAGS 0x0L\r">>$APPVERSION_FILE - echo -e "\r">>$APPVERSION_FILE - echo -e '#define APP_COMMIT_DATE "'$month $day $year'"\r'>>$APPVERSION_FILE - echo -e '#define APP_COMMIT_TIME "'$hours'"\r'>>$APPVERSION_FILE - echo -e "\r">>$APPVERSION_FILE + echo -e "#define APP_VERSION_C $MAJOR,$MINOR,$MAINTENANCE,$COMMIT_COUNT\r">>"$APPVERSION_FILE" + echo -e '#define APP_VERSION_STRD "'$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT'"\r'>>"$APPVERSION_FILE" + echo -e "#define APP_VERSION_FLAGS 0x0L\r">>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e '#define APP_COMMIT_DATE "'$month $day $year'"\r'>>"$APPVERSION_FILE" + echo -e '#define APP_COMMIT_TIME "'$hours'"\r'>>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" - echo -e '#define APP_COMMIT_SHA "'$COMMIT_SHA'"\r'>>$APPVERSION_FILE - echo -e '#define APP_COMMIT_URL "'$COMMIT_URL'"\r'>>$APPVERSION_FILE - echo -e "\r">>$APPVERSION_FILE - echo -e "#endif //__APPVERSION_H__\r">>$APPVERSION_FILE + echo -e '#define APP_COMMIT_SHA "'$COMMIT_SHA'"\r'>>"$APPVERSION_FILE" + echo -e '#define APP_COMMIT_URL "'$COMMIT_URL'"\r'>>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e "#endif //__APPVERSION_H__\r">>"$APPVERSION_FILE" } # Initialise