Skip to content

Commit a01d06f

Browse files
committed
Enable base example on Windows
Replace strcpy() with util_strncpy() in the base example. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent d194370 commit a01d06f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.github/workflows/pr_push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989

9090
- name: Run examples
9191
working-directory: ${{github.workspace}}/build
92-
run: ctest --output-on-failure --test-dir examples
92+
run: ctest --output-on-failure --test-dir examples -C Release
9393

9494
CodeStyle:
9595
name: Coding style

examples/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if(UMF_BUILD_OS_MEMORY_PROVIDER
1111
LIBS umf
1212
scalable_pool)
1313
target_include_directories(${EXAMPLE_NAME} PRIVATE
14+
${UMF_CMAKE_SOURCE_DIR}/src/utils
1415
${UMF_CMAKE_SOURCE_DIR}/include)
1516

1617
add_test(NAME ${EXAMPLE_NAME}
@@ -19,6 +20,18 @@ if(UMF_BUILD_OS_MEMORY_PROVIDER
1920

2021
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
2122

23+
if(WINDOWS)
24+
# append PATH to DLLs
25+
set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>")
26+
if(LIBHWLOC_DLL_DIRS)
27+
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_DLL_DIRS}")
28+
endif()
29+
if(LIBTBB_DLL_DIRS)
30+
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBTBB_DLL_DIRS}")
31+
endif()
32+
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${DLL_PATH_LIST}")
33+
endif()
34+
2235
install(FILES basic/basic.c
2336
DESTINATION "${CMAKE_INSTALL_DOCDIR}/examples")
2437

examples/basic/basic.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <stdio.h>
1414
#include <string.h>
1515

16+
#include "utils_common.h"
17+
1618
int main(void) {
1719
// A result object for storing UMF API result status
1820
umf_result_t res;
@@ -45,9 +47,11 @@ int main(void) {
4547
goto memory_provider_destroy;
4648
}
4749

50+
const char *strSource = "Allocated memory at";
51+
4852
// Write to the allocated memory
4953
memset(ptr_provider, '\0', alloc_size);
50-
strcpy(ptr_provider, "Allocated memory at");
54+
util_strncpy(ptr_provider, alloc_size, strSource, strlen(strSource) + 1);
5155
printf("%s %p with the memory provider at %p\n", (char *)ptr_provider,
5256
(void *)ptr_provider, (void *)provider);
5357

@@ -83,7 +87,7 @@ int main(void) {
8387
}
8488

8589
// Write a string to allocated memory
86-
strcpy(ptr, "Allocated memory at");
90+
util_strncpy(ptr, alloc_size, strSource, strlen(strSource) + 1);
8791
printf("%s %p\n", ptr, (void *)ptr);
8892

8993
// Retrieve a memory pool from a pointer, available with memory tracking

0 commit comments

Comments
 (0)