Currently NTSTATUS and WERROR structure based types are defined as: #if defined(HAVE_IMMEDIATE_STRUCTURES) typedef struct {uint32_t v;} WERROR; #define W_ERROR_V(x) ((x).v) and... #if defined(HAVE_IMMEDIATE_STRUCTURES) typedef struct {uint32_t v;} NTSTATUS; #define NT_STATUS_V(x) ((x).v) With matching 'v' members, it's easy to make silly mistakes such as: ... WERROR werr; werr = my_fn(); /* XXX returns WERROR type */ if (NT_STATUS_IS_OK(werr) || (NT_STATUS_EQUAL(werr, NT_STATUS_OBJECT_NAME_COLLISION))) { ... With differing members, the compiler catches attempts to use [NT_STATUS|W_ERROR]_IS_OK() and [NT_STATUS|W_ERROR]_EQUAL() with incorrect types: diff --git a/libcli/util/werror.h b/libcli/util/werror.h index b490974..4c14b7f 100644 --- a/libcli/util/werror.h +++ b/libcli/util/werror.h @@ -30,9 +30,9 @@ */ #if defined(HAVE_IMMEDIATE_STRUCTURES) -typedef struct {uint32_t v;} WERROR; +typedef struct {uint32_t w;} WERROR; #define W_ERROR(x) ((WERROR) { x }) -#define W_ERROR_V(x) ((x).v) +#define W_ERROR_V(x) ((x).w) #else typedef uint32_t WERROR; #define W_ERROR(x) (x)
Ready for review: http://git.samba.org/?p=ddiss/samba.git;a=shortlog;h=refs/heads/bso8715_catch_ntstatus_werr_swaps The following changes since commit c3a7573a849bfbc88feed43f12b6bdc71300ab0a: s3-spoolss: fix incorrect error check type (2012-01-22 05:03:36 +0100) are available in the git repository at: git://git.samba.org/ddiss/samba.git bso8715_catch_ntstatus_werr_swaps David Disseldorp (2): lib: use differing NTSTATUS and WERROR struct members common: fix incorrect error check types libcli/util/werror.h | 4 ++-- source3/printing/nt_printing.c | 2 +- source3/rpc_client/cli_winreg_spoolss.c | 2 +- source4/lib/registry/tools/regtree.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
+1. Put it in asap please :-) Volker
Already in the process of adding this to master :-). This is *excellent* work !
Thanks for the review Volker and Jeremy :) This change is in master as: commit af6bf7714d8eb4cd3ac4e9f9ab674326e74c6a49 lib: use differing NTSTATUS and WERROR struct members IMO a 3.6 merge is not valuable, closing.