diff --git a/.github/workflows/macosx-clang-build.yml b/.github/workflows/macosx-clang-build.yml index a51d721..dfb0277 100644 --- a/.github/workflows/macosx-clang-build.yml +++ b/.github/workflows/macosx-clang-build.yml @@ -32,7 +32,7 @@ jobs: uses: lukka/run-vcpkg@v11.0 with: vcpkgDirectory: '${{ github.workspace }}/vcpkg' - vcpkgGitCommitId: 'b619a233fbf7b2c9765fb4458f3ecb05bd3166e3' + vcpkgGitCommitId: 'efca044b75fbf481d6650ce4d3b223d8af94f7a7' - name: run build uses: lukka/run-cmake@v10.3 diff --git a/.github/workflows/ubuntu-gcc-build.yml b/.github/workflows/ubuntu-gcc-build.yml index 47d272d..a8d2889 100644 --- a/.github/workflows/ubuntu-gcc-build.yml +++ b/.github/workflows/ubuntu-gcc-build.yml @@ -29,7 +29,7 @@ jobs: uses: lukka/run-vcpkg@v11.0 with: vcpkgDirectory: '${{ github.workspace }}/vcpkg' - vcpkgGitCommitId: 'b619a233fbf7b2c9765fb4458f3ecb05bd3166e3' + vcpkgGitCommitId: 'efca044b75fbf481d6650ce4d3b223d8af94f7a7' - name: run build uses: lukka/run-cmake@v10.3 diff --git a/.github/workflows/windows-msvc-build.yml b/.github/workflows/windows-msvc-build.yml index 64d16b2..2d43b13 100644 --- a/.github/workflows/windows-msvc-build.yml +++ b/.github/workflows/windows-msvc-build.yml @@ -24,7 +24,7 @@ jobs: uses: lukka/run-vcpkg@v11.0 with: vcpkgDirectory: '${{ github.workspace }}/vcpkg' - vcpkgGitCommitId: 'b619a233fbf7b2c9765fb4458f3ecb05bd3166e3' + vcpkgGitCommitId: 'efca044b75fbf481d6650ce4d3b223d8af94f7a7' - name: run build uses: lukka/run-cmake@v10.3 diff --git a/seika/utils/se_string_util.c b/seika/utils/se_string_util.c index 06dd880..2cb61dc 100644 --- a/seika/utils/se_string_util.c +++ b/seika/utils/se_string_util.c @@ -32,12 +32,18 @@ void se_strcpy(char* destination, const char* source) { strcpy(destination, source); } -void se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount) { +bool se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount) { #if defined(WIN32) || defined(WIN64) - strncpy_s(destination, sizeInBytes, source, maxCount); + if (strncpy_s(destination, sizeInBytes, source, maxCount) != 0) { + return false; + } #else strncpy(destination, source, maxCount); + if (maxCount > 0) { + destination[maxCount - 1] = '\0'; + } #endif + return true; } void se_strcat(char* destination, const char* source) { diff --git a/seika/utils/se_string_util.h b/seika/utils/se_string_util.h index d88318c..0abeaec 100644 --- a/seika/utils/se_string_util.h +++ b/seika/utils/se_string_util.h @@ -8,7 +8,7 @@ char* se_strdup(const char* string); // Copies string from a void pointer and allocated new memory char* se_strdup_from_memory(void* data, size_t size); void se_strcpy(char* destination, const char* source); -void se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount); +bool se_strncpy(char* destination, size_t sizeInBytes, const char* source, size_t maxCount); void se_strcat(char* destination, const char* source); void se_strncat(char* destination, const char* source, size_t sizeInBytes); const char* se_bool_to_string(bool value); diff --git a/test/main.c b/test/main.c index 5d0fe9f..244aaf7 100644 --- a/test/main.c +++ b/test/main.c @@ -155,6 +155,17 @@ void seika_string_utils_test(void) { // Test string dup char* filePath = se_strdup("project.cscn"); TEST_ASSERT_EQUAL_STRING("project.cscn", filePath); + // Test string copy funcs + char stringTestBuffer[256]; + se_strcpy(stringTestBuffer, "test"); + TEST_ASSERT_EQUAL_STRING("test", stringTestBuffer); + se_strncpy(stringTestBuffer, sizeof(stringTestBuffer), "other test", 5); + TEST_ASSERT_EQUAL_STRING("other", stringTestBuffer); + // Test string cat funcs + se_strcat(stringTestBuffer, " message"); + TEST_ASSERT_EQUAL_STRING("other message", stringTestBuffer); + se_strncat(stringTestBuffer, " okay", sizeof(char) * 3); + TEST_ASSERT_EQUAL_STRING("other message ok", stringTestBuffer); // Test trim char* filePathWithoutExtension = se_str_trim(filePath, '.'); TEST_ASSERT_EQUAL_STRING("project", filePathWithoutExtension); diff --git a/vcpkg.json b/vcpkg.json index 1d36af2..5e88817 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,5 +11,5 @@ "version>=": "2.12.1" } ], - "builtin-baseline": "91393faf123c4f1d22ef3dbfb4ec03531bac907a" + "builtin-baseline": "efca044b75fbf481d6650ce4d3b223d8af94f7a7" }