浏览代码

refactor & fix: 修复Clang编译警告

SongZihuan 3 年之前
父节点
当前提交
fb4b5f84fc

+ 2 - 2
CMakeLists.txt

@@ -52,8 +52,8 @@ if (MSVC)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
 else()
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic -ansi")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic -ansi")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic")
 endif()
 
 # 相关参数

+ 1 - 1
include/tool/tool-exception.h

@@ -9,7 +9,7 @@ namespace aFuntool {
         std::string message;
     public:
         AFUN_INLINE explicit aFunException(std::string msg);
-        virtual const char *what();
+        [[nodiscard]] const char *what() const noexcept override;
         [[nodiscard]] AFUN_INLINE const std::string &getMessage() const;
     };
 

+ 2 - 2
src/core/code.cpp

@@ -192,7 +192,7 @@ RETURN:
         }
 
         MD5Final(md5, (unsigned char *) md5_value);
-        for (int i = 0; i < aFuntool::MD5_SIZE; i++)
+        for (size_t i = 0; i < aFuntool::MD5_SIZE; i++)
             snprintf((char *) md5str + i * 2, 2 + 1, "%02x", md5_value[i]);
         return md5str;
     }
@@ -522,7 +522,7 @@ if(!(write)){           \
             MD5Update(md5, (unsigned char *) "start", 5);
 
         MD5Final(md5, (unsigned char *) md5_value);
-        for (int i = 0; i < aFuntool::MD5_SIZE; i++)
+        for (size_t i = 0; i < aFuntool::MD5_SIZE; i++)
             snprintf((char *) md5str + i * 2, 2 + 1, "%02x", md5_value[i]);
         return md5str;
     }

+ 1 - 1
src/core/object-value.cpp

@@ -198,7 +198,7 @@ namespace aFuncore {
         auto none = new Object("None", inter);
         stream.pushMessage("NORMAL", new NormalMessage(none));
         none->delReference();
-        aFuntool::cout << "Import " << import << "\n";
+        aFuntool::cout << "Import " << import << " : " << call_code << "\n";
     }
 
     ImportFunction::CallFunc::~CallFunc() {

+ 1 - 1
src/tool/exception.cpp

@@ -1,7 +1,7 @@
 #include "tool-exception.h"
 
 namespace aFuntool {
-    const char *aFunException::what() {
+    const char *aFunException::what() const noexcept {
         return message.c_str();
     }
 }

+ 1 - 1
src/tool/md5.cpp

@@ -215,7 +215,7 @@ namespace aFuntool {
         fileClose(fd);
         MD5Final(md5, md5_value);
 
-        for (int i = 0; i < MD5_SIZE; i++)
+        for (size_t i = 0; i < MD5_SIZE; i++)
             snprintf(md5str + i * 2, 2 + 1, "%02x", md5_value[i]);
 
         return md5str;

+ 14 - 1
src/tool/string.cpp

@@ -24,7 +24,11 @@ namespace aFuntool {
         if (str != nullptr) {
             auto size = STR_LEN(str);
             char *tmp = NEW_STR(size);
+#ifdef aFunWIN32_NO_CYGWIN
             strcpy_s(tmp, size + 1, str);
+#else
+            strcpy(tmp, str);
+#endif
             return tmp;
         }
         return nullptr;
@@ -45,9 +49,18 @@ namespace aFuntool {
 
         auto size = STR_LEN(first) + STR_LEN(second);
         char *new_str = NEW_STR(size);
+#ifdef aFunWIN32_NO_CYGWIN
         strcat_s(new_str, size + 1, first);
-        if (second != nullptr)
+#else
+        strcat(new_str, first);
+#endif
+        if (second != nullptr) {
+#ifdef aFunWIN32_NO_CYGWIN
             strcat_s(new_str, size + 1, second);
+#else
+            strcat(new_str, second);
+#endif
+        }
 
         if (free_first) {
             auto free_ = const_cast<char *>(first);

+ 5 - 5
test/src/tool-byte.cpp

@@ -58,11 +58,11 @@ int main() {
 
     if (rtest8 != test8 || rtest16 != test16 || rtest32 != test32 || rtest64 != test64 || rtestStr != testStr) {
         printf("error.\n");
-        printf("rtest8 = %d, test = %d\n", rtest8, test8);
-        printf("rtest16 = %d, test = %d\n", rtest16, test16);
-        printf("rtest32 = %d, test = %d\n", rtest32, test32);
-        printf("rtest64 = %lld, test = %lld\n", rtest64, test64);
-        printf("rtestStr = %s\ntestStr = %s\n", rtestStr.c_str(), testStr.c_str());
+        aFuntool::cout << "rtest8: " << rtest8 << ", test: " << test8 << "\n";
+        aFuntool::cout << "rtest16: " << rtest16 << ", test: " << test16 << "\n";
+        aFuntool::cout << "rtest32: " << rtest32 << ", test: " << test32 << "\n";
+        aFuntool::cout << "rtest64: " << rtest64 << ", test: " << test64 << "\n";
+        aFuntool::cout << "rtestStr: " << rtestStr << "\ntestStr: " << testStr << "\n";
         return EXIT_FAILURE;
     }
 

+ 4 - 4
test/src/tool-utf.cpp

@@ -2,14 +2,14 @@
 #include <clocale>
 using namespace aFuntool;
 
-int main(int argc, char **argv) {
+int main() {
+    setlocale(LC_ALL, "");
+
+#ifdef aFunWIN32_NO_CYGWIN
     wchar_t *tmp;
     const wchar_t *tmp2 = L"你好";
     const char *tmp3 = "你好";
 
-    setlocale(LC_ALL, "");
-
-#ifdef aFunWIN32_NO_CYGWIN
     convertWideByte(&tmp, tmp3, CP_UTF8);
 
     std::wcout << tmp << std::endl;