From 351a30f1861c0596ed4834fadc96c88ccd35fa98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 8 Feb 2023 00:28:24 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-windows:=20=D0=BD=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=85=D0=BE=D0=B4=D1=83=D0=B5=D0=BC=20=D1=81=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=20=D0=BF=D0=BE=D0=B4=20=D0=B1=D1=83=D1=84=D0=B5=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20wchar-=D0=BF=D1=80=D0=B5=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=83=D1=82=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.c | 24 ++++++++++++++++-------- src/osal.h | 12 ++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/core.c b/src/core.c index 4eb57d6f..e32e9ba8 100644 --- a/src/core.c +++ b/src/core.c @@ -14486,9 +14486,11 @@ __cold int mdbx_env_turn_for_recovery(MDBX_env *env, unsigned target) { __cold int mdbx_env_open_for_recovery(MDBX_env *env, const char *pathname, unsigned target_meta, bool writeable) { #if defined(_WIN32) || defined(_WIN64) - const wchar_t *pathnameW = nullptr; + wchar_t *pathnameW = nullptr; OSAL_MB2WIDE(pathname, pathnameW); - return mdbx_env_open_for_recoveryW(env, pathnameW, target_meta, writeable); + int rc = mdbx_env_open_for_recoveryW(env, pathnameW, target_meta, writeable); + osal_free(pathnameW); + return rc; } __cold int mdbx_env_open_for_recoveryW(MDBX_env *env, const wchar_t *pathname, @@ -14675,9 +14677,11 @@ __cold static int handle_env_pathname(MDBX_handle_env_pathname *ctx, __cold int mdbx_env_delete(const char *pathname, MDBX_env_delete_mode_t mode) { #if defined(_WIN32) || defined(_WIN64) - const wchar_t *pathnameW = nullptr; + wchar_t *pathnameW = nullptr; OSAL_MB2WIDE(pathname, pathnameW); - return mdbx_env_deleteW(pathnameW, mode); + int rc = mdbx_env_deleteW(pathnameW, mode); + osal_free(pathnameW); + return rc; } __cold int mdbx_env_deleteW(const wchar_t *pathname, @@ -14766,9 +14770,11 @@ __cold int mdbx_env_deleteW(const wchar_t *pathname, __cold int mdbx_env_open(MDBX_env *env, const char *pathname, MDBX_env_flags_t flags, mdbx_mode_t mode) { #if defined(_WIN32) || defined(_WIN64) - const wchar_t *pathnameW = nullptr; + wchar_t *pathnameW = nullptr; OSAL_MB2WIDE(pathname, pathnameW); - return mdbx_env_openW(env, pathnameW, flags, mode); + int rc = mdbx_env_openW(env, pathnameW, flags, mode); + osal_free(pathnameW); + return rc; } __cold int mdbx_env_openW(MDBX_env *env, const wchar_t *pathname, @@ -21772,9 +21778,11 @@ __cold int mdbx_env_copy2fd(MDBX_env *env, mdbx_filehandle_t fd, __cold int mdbx_env_copy(MDBX_env *env, const char *dest_path, MDBX_copy_flags_t flags) { #if defined(_WIN32) || defined(_WIN64) - const wchar_t *dest_pathW = nullptr; + wchar_t *dest_pathW = nullptr; OSAL_MB2WIDE(dest_path, dest_pathW); - return mdbx_env_copyW(env, dest_pathW, flags); + int rc = mdbx_env_copyW(env, dest_pathW, flags); + osal_free(dest_pathW); + return rc; } LIBMDBX_API int mdbx_env_copyW(MDBX_env *env, const wchar_t *dest_path, diff --git a/src/osal.h b/src/osal.h index 02447376..a8e50a20 100644 --- a/src/osal.h +++ b/src/osal.h @@ -765,12 +765,16 @@ MDBX_INTERNAL_FUNC size_t osal_mb2w(wchar_t *dst, size_t dst_n, const char *src, const char *const from_tmp = (FROM); \ const size_t from_mblen = strlen(from_tmp); \ const size_t to_wlen = osal_mb2w(nullptr, 0, from_tmp, from_mblen); \ - if (to_wlen < 1 || to_wlen > /* MAX_PATH */ INT16_MAX) \ + if (unlikely(to_wlen < 1 || to_wlen > /* MAX_PATH */ INT16_MAX)) \ return ERROR_INVALID_NAME; \ - wchar_t *const to_tmp = _alloca((to_wlen + 1) * sizeof(wchar_t)); \ - if (to_wlen + 1 != \ - osal_mb2w(to_tmp, to_wlen + 1, from_tmp, from_mblen + 1)) \ + wchar_t *const to_tmp = osal_malloc((to_wlen + 1) * sizeof(wchar_t)); \ + if (unlikely(!to_tmp)) \ + return MDBX_ENOMEM; \ + if (unlikely(to_wlen + 1 != \ + osal_mb2w(to_tmp, to_wlen + 1, from_tmp, from_mblen + 1))) { \ + osal_free(to_tmp); \ return ERROR_INVALID_NAME; \ + } \ (TO) = to_tmp; \ } while (0)