From 928014c88a77ed9dcec0621f9aff01c9a28a5d9b Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Fri, 1 Sep 2017 17:43:07 +0300 Subject: [PATCH 1/3] mdbx: fix coverity warning (minor). Change-Id: Iaa4f8d6611139a9c500b3d803c7fe1fbcc8591e1 --- tutorial/sample-mdbx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorial/sample-mdbx.c b/tutorial/sample-mdbx.c index 39adba02..f5188cf4 100644 --- a/tutorial/sample-mdbx.c +++ b/tutorial/sample-mdbx.c @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) { rc = mdbx_env_create(&env); if (rc != MDBX_SUCCESS) { fprintf(stderr, "mdbx_env_create: (%d) %s\n", rc, mdbx_strerror(rc)); - return 0; + goto bailout; } rc = mdbx_env_open(env, "./example-db", MDBX_NOSUBDIR | MDBX_COALESCE | MDBX_LIFORECLAIM, 0664); From e6e92134a6570cdf9cbff78460105ad5db0ceedc Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 5 Sep 2017 20:56:11 +0300 Subject: [PATCH 2/3] mdbx: fix PVS-Studio warnings. --- src/mdbx.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index 89fe3cee..eb1478be 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -4188,8 +4188,9 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags, if ((flags & (MDBX_NOSYNC | MDBX_NOMETASYNC)) == 0) { mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0); if (flags & MDBX_WRITEMAP) { - const size_t offset = (uint8_t *)container_of(head, MDBX_page, mp_meta) - - env->me_dxb_mmap.dxb; + const size_t offset = + ((uint8_t *)container_of(head, MDBX_page, mp_meta)) - + env->me_dxb_mmap.dxb; const size_t paged_offset = offset & ~(env->me_os_psize - 1); const size_t paged_length = mdbx_roundup2( env->me_psize + offset - paged_offset, env->me_os_psize); @@ -4852,7 +4853,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, int lck_rc) { head->mm_datasync_sign = MDBX_DATASIGN_WEAK; head->mm_txnid_b = 0; const size_t offset = - (uint8_t *)container_of(head, MDBX_page, mp_meta) - + ((uint8_t *)container_of(head, MDBX_page, mp_meta)) - env->me_dxb_mmap.dxb; const size_t paged_offset = offset & ~(env->me_os_psize - 1); const size_t paged_length = mdbx_roundup2( @@ -10750,9 +10751,10 @@ int mdbx_txn_straggler(MDBX_txn *txn, int *percent) MDBX_env *env = txn->mt_env; if (unlikely((txn->mt_flags & MDBX_RDONLY) == 0)) { - *percent = - (int)((txn->mt_next_pgno * UINT64_C(100) + txn->mt_end_pgno / 2) / - txn->mt_end_pgno); + if (percent) + *percent = + (int)((txn->mt_next_pgno * UINT64_C(100) + txn->mt_end_pgno / 2) / + txn->mt_end_pgno); return -1; } From ee9d0903c8086e2769ae4dfccc940fbb124cd38d Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 5 Sep 2017 20:58:03 +0300 Subject: [PATCH 3/3] mdbx: use for Windows. --- src/osal.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/osal.c b/src/osal.c index c3b50c92..d9026cfa 100644 --- a/src/osal.c +++ b/src/osal.c @@ -17,6 +17,8 @@ #include "./bits.h" #if defined(_WIN32) || defined(_WIN64) +#include + static int waitstatus2errcode(DWORD result) { switch (result) { case WAIT_OBJECT_0: @@ -53,25 +55,6 @@ static int ntstatus2errcode(NTSTATUS status) { * ntdll.dll, which is not linked by default in user code. */ #pragma comment(lib, "ntdll.lib") -#ifndef NT_SUCCESS -#define NT_SUCCESS(x) ((x) >= 0) -#define STATUS_SUCCESS ((NTSTATUS)0) -#endif -typedef struct _UNICODE_STRING { - USHORT Length; - USHORT MaximumLength; - PWSTR Buffer; -} UNICODE_STRING, *PUNICODE_STRING; - -typedef struct _OBJECT_ATTRIBUTES { - ULONG Length; - HANDLE RootDirectory; - PUNICODE_STRING ObjectName; - ULONG Attributes; - PVOID SecurityDescriptor; - PVOID SecurityQualityOfService; -} OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; - extern NTSTATUS NTAPI NtCreateSection( OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN OPTIONAL POBJECT_ATTRIBUTES ObjectAttributes, @@ -104,14 +87,6 @@ extern NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN OUT PULONG RegionSize, IN ULONG FreeType); -typedef struct _IO_STATUS_BLOCK { - union { - NTSTATUS Status; - PVOID Pointer; - }; - ULONG_PTR Information; -} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; - #ifndef FILE_PROVIDER_CURRENT_VERSION typedef struct _FILE_PROVIDER_EXTERNAL_INFO_V1 { ULONG Version;