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 diff --git a/src/alloc.c b/src/alloc.c index 76342771..bbededcb 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -693,12 +693,13 @@ MI_ALLOC_API1(mi_decl_restrict char*, strdup, mi_heap_t*, heap, const char*, s) MI_ALLOC_API2(mi_decl_restrict char*, strndup, mi_heap_t*, heap, const char*, s, size_t, n) { if (s == NULL) return NULL; - size_t m = strlen(s); - if (n > m) n = m; - char* t = (char*)MI_SOURCE_ARG(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_SOURCE_ARG(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; }