From 55033efef64b2a4c068b645a0861919c3987f93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 16 Sep 2026 11:06:31 +0200 Subject: [PATCH 1/2] yangupdate BUGFIX Windows test link errors `LIBYANG_BUILD` was never defined for the `yang_update` static lib, so `LIBYANG_API_DECL` expanded to `dllimport` instead of `dllexport` on MSVC, breaking the `yangupdate_find_mod1`/`complex_update` tests with LNK2019. It is `PUBLIC`, not `PRIVATE`, because `test.c` doesn't compile `yang_update.c` directly, it only links the lib, and `PRIVATE` defines won't propagate to linkers. Co-Authored-By: Claude Sonnet 5 --- tools/update/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/update/CMakeLists.txt b/tools/update/CMakeLists.txt index a734688dbf..49bdf2cd64 100644 --- a/tools/update/CMakeLists.txt +++ b/tools/update/CMakeLists.txt @@ -42,6 +42,7 @@ endif() # yang update library add_library(${LIB_NAME} STATIC ${lib_src}) +target_compile_definitions(${LIB_NAME} PUBLIC LIBYANG_BUILD) target_include_directories(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_BINARY_DIR}) get_target_property(yang_linked_libraries yang LINK_LIBRARIES) target_link_libraries(${LIB_NAME} $ ${yang_linked_libraries}) From 1161c43bf033cd2a00aa9a0f63c8bc75717e5ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 16 Sep 2026 11:14:43 +0200 Subject: [PATCH 2/2] yangupdate BUGFIX Windows CRLF text-mode fread mismatch All three spots read a whole file with fopen(path, "r") + ftell()-sized fread(), then null-terminate at the ftell() size. On Windows, text-mode fread() collapses \r\n to \n, so it returns fewer bytes than ftell() reported whenever the file has CRLF line endings. That left the tail of each buffer as uninitialized heap garbage instead of content. In yang_update.c this fed a YANG parser garbage after the real module text, failing with "Trailing garbage ... after module, expected end-of-input." In the two test files it just desynced the compared buffer's length. Use fread()'s actual return value to size/terminate the buffer instead of trusting ftell(), regardless of the file's on-disk line endings. Opening in binary mode instead would dodge the byte-count mismatch too, but the two test files compare against libyang's own LF-only printer output, so a CRLF checkout would then fail on stray \r's instead - a checkout-dependent bug rather than a fixed one. Co-Authored-By: Claude Sonnet 5 --- tests/utests/schema_comparison/test_schema_comparison.c | 2 +- tests/yangupdate/complex_update/test.c | 6 +++--- tools/update/yang_update.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/utests/schema_comparison/test_schema_comparison.c b/tests/utests/schema_comparison/test_schema_comparison.c index 5beac6b27e..d10fce14be 100644 --- a/tests/utests/schema_comparison/test_schema_comparison.c +++ b/tests/utests/schema_comparison/test_schema_comparison.c @@ -135,7 +135,7 @@ schema_comparison(struct sc_state *st, const char *module_name) fseek(st->f, 0, SEEK_SET); st->exp = malloc(size + 1); assert_non_null(st->exp); - assert_int_equal(size, fread(st->exp, 1, size, st->f)); + size = fread(st->exp, 1, size, st->f); st->exp[size] = '\0'; /* compare the output */ diff --git a/tests/yangupdate/complex_update/test.c b/tests/yangupdate/complex_update/test.c index 6eae091823..ceeba1007a 100644 --- a/tests/yangupdate/complex_update/test.c +++ b/tests/yangupdate/complex_update/test.c @@ -104,7 +104,7 @@ test_update_01_01_to_01_20(void **state) rewind(st->f); st->str1 = malloc(size + 1); assert_non_null(st->str1); - fread(st->str1, 1, size, st->f); + size = fread(st->str1, 1, size, st->f); st->str1[size] = '\0'; assert_string_equal(st->str2, st->str1); } @@ -140,7 +140,7 @@ test_update_01_10_to_01_15(void **state) rewind(st->f); st->str1 = malloc(size + 1); assert_non_null(st->str1); - fread(st->str1, 1, size, st->f); + size = fread(st->str1, 1, size, st->f); st->str1[size] = '\0'; assert_string_equal(st->str2, st->str1); } @@ -177,7 +177,7 @@ test_update_01_15_to_01_20(void **state) rewind(st->f); st->str1 = malloc(size + 1); assert_non_null(st->str1); - fread(st->str1, 1, size, st->f); + size = fread(st->str1, 1, size, st->f); st->str1[size] = '\0'; assert_string_equal(st->str2, st->str1); } diff --git a/tools/update/yang_update.c b/tools/update/yang_update.c index 0ea811a09d..f036d3e38a 100644 --- a/tools/update/yang_update.c +++ b/tools/update/yang_update.c @@ -583,7 +583,7 @@ yu_module_imp_clb(const char *mod_name, const char *mod_rev, const char *submod_ rc = LY_EMEM; goto cleanup; } - fread(data, 1, size, f); + size = fread(data, 1, size, f); data[size] = '\0'; *format = fmt;