From 6f03be2d3acd66ae6925ddc3cce4b14032ec5d51 Mon Sep 17 00:00:00 2001 From: Jiaye Wu Date: Tue, 14 Apr 2020 12:54:35 +0800 Subject: [PATCH 1/2] Fix Windows builds on Azure Pipelines Currently, all Windows builds are using `Debug|x64` configuration. For example, you can see the CTest steps with Release build cost 20+ seconds, which means it is using the debug binary. --- azure-pipelines.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6c7bad96..954ec15d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -18,12 +18,15 @@ jobs: Debug: BuildType: debug cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON + MSBuildConfiguration: Debug Release: BuildType: release cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release + MSBuildConfiguration: Release Secure: BuildType: secure cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON + MSBuildConfiguration: Release steps: - task: CMake@1 inputs: @@ -32,6 +35,7 @@ jobs: - task: MSBuild@1 inputs: solution: $(BuildType)/libmimalloc.sln + configuration: '$(MSBuildConfiguration)' - script: | cd $(BuildType) ctest From 1116c0df2ea85bd03b4cfe38b2bd11afda090784 Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 14 Apr 2020 17:42:30 -0700 Subject: [PATCH 2/2] fix strnlen do not search beyond n characters, issue #228 --- src/alloc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index d7b8219e..90a1f461 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -649,12 +649,13 @@ mi_decl_restrict char* mi_strdup(const char* s) mi_attr_noexcept { // `strndup` using mi_malloc mi_decl_restrict char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n) mi_attr_noexcept { if (s == NULL) return NULL; - size_t m = strlen(s); - if (n > m) n = m; - char* t = (char*)mi_heap_malloc(heap, n+1); + const char* end = (const char*)memchr(s, 0, n); // find end of string in the first `n` characters (returns NULL if not found) + const size_t m = (end != NULL ? (end - s) : n); // `m` is the minimum of `n` or the end-of-string + mi_assert_internal(m <= n); + char* t = (char*)mi_heap_malloc(heap, m+1); if (t == NULL) return NULL; - memcpy(t, s, n); - t[n] = 0; + memcpy(t, s, m); + t[m] = 0; return t; }