From 393f098c8153dba0282546cb48b47b4dbe4fc217 Mon Sep 17 00:00:00 2001 From: Francisco Garcia Date: Fri, 6 Dec 2024 10:38:16 +0100 Subject: [PATCH] Fix macOS issue in dlib_open() --- Changelog.md | 9 +++++---- prj/build.txt | 2 +- src/osbs/unix/dlib.c | 31 ++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Changelog.md b/Changelog.md index a2dd2b9a..cd441eeb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,15 +5,16 @@ ### Added - `.clang-format` file. [Issue](https://github.com/frang75/nappgui_src/issues/161). [Commit](https://github.com/frang75/nappgui_src/commit/40356b8b17a7cb1f39c2bdfa3c7d4e8ce6ef35d8). -- `arrst_insert_n0()`. [Doc](). [Commit](). -- `listbox_del_elem()`. [Doc](). [Commit](). -- `bfile_rename()`. [Doc](). [Commit](). +- `arrst_insert_n0()`. [Doc](https://nappgui.com/en/core/arrst.html#f24). [Commit](https://github.com/frang75/nappgui_src/commit/50887ca89b6a844f6b683ca1d2937f3a03cfb004). +- `listbox_del_elem()`. [Doc](https://nappgui.com/en/gui/listbox.html#f9). [Commit](https://github.com/frang75/nappgui_src/commit/50887ca89b6a844f6b683ca1d2937f3a03cfb004). +- `bfile_rename()`. [Doc](https://nappgui.com/en/osbs/bfile.html#f21). [Commit](https://github.com/frang75/nappgui_src/commit/50887ca89b6a844f6b683ca1d2937f3a03cfb004). ### Fixed - Issue in `Layout` when window becomes very small. [Commit](https://github.com/frang75/nappgui_src/commit/3d616fa82e072b6c46f4cf196df0516912ab634c). - Issue in `bmath_prec()`. [Commit](https://github.com/frang75/nappgui_src/commit/062d2a69ea187c2c983b0db02f022a7552295a19). -- Vulnerability in `str_upd()`. [Commit](). +- Vulnerability in `str_upd()`. [Commit](https://github.com/frang75/nappgui_src/commit/50887ca89b6a844f6b683ca1d2937f3a03cfb004). +- Issue in `dlib_open()` in macOS. [Issue](https://github.com/frang75/nappgui_src/issues/164). [Commit](). ### Improved diff --git a/prj/build.txt b/prj/build.txt index 38c598d4..43284e36 100644 --- a/prj/build.txt +++ b/prj/build.txt @@ -1 +1 @@ -5597 +5645 diff --git a/src/osbs/unix/dlib.c b/src/osbs/unix/dlib.c index 3902fae8..3e5ec846 100644 --- a/src/osbs/unix/dlib.c +++ b/src/osbs/unix/dlib.c @@ -21,7 +21,7 @@ static const char_t *i_LIB_PREFIX = "lib"; static const char_t *i_LIB_SUFIX = ".so"; #elif defined(__MACOS__) static const char_t *i_LIB_PREFIX = "lib"; -static const char_t *i_LIB_SUFIX = ".so"; +static const char_t *i_LIB_SUFIX = ".dylib"; #else #error Unknown platform #endif @@ -32,29 +32,38 @@ static const char_t *i_LIB_SUFIX = ".so"; DLib *dlib_open(const char_t *path, const char_t *libname) { - char_t name[512]; + uint32_t size = 0; + char_t *pathname = NULL; void *lib = NULL; cassert_no_null(libname); + size += 2; /* Backslash and null terminator */ + size += blib_strlen(libname); + size += blib_strlen(i_LIB_PREFIX); + size += blib_strlen(i_LIB_SUFIX); if (path != NULL && path[0] != '\0') { uint32_t n = blib_strlen(path); - blib_strcpy(name, sizeof(name), path); + size += n; + pathname = cast(bmem_malloc(size), char_t); + blib_strcpy(pathname, size, path); if (path[n - 1] != '/') - blib_strcat(name, sizeof(name), "/"); - blib_strcat(name, sizeof(name), i_LIB_PREFIX); - blib_strcat(name, sizeof(name), libname); - blib_strcat(name, sizeof(name), i_LIB_SUFIX); + blib_strcat(pathname, size, "/"); + blib_strcat(pathname, size, i_LIB_PREFIX); + blib_strcat(pathname, size, libname); + blib_strcat(pathname, size, i_LIB_SUFIX); } else { - blib_strcpy(name, sizeof(name), i_LIB_PREFIX); - blib_strcat(name, sizeof(name), libname); - blib_strcat(name, sizeof(name), i_LIB_SUFIX); + pathname = cast(bmem_malloc(size), char_t); + blib_strcpy(pathname, size, i_LIB_PREFIX); + blib_strcat(pathname, size, libname); + blib_strcat(pathname, size, i_LIB_SUFIX); } - lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL); + lib = dlopen(pathname, RTLD_LAZY | RTLD_LOCAL); + bmem_free(cast(pathname, byte_t)); if (lib != NULL) { _osbs_dlib_alloc();