Skip to content

Fix WDF_PTR_GET_OFFSET operator precedence problem #25

Description

@axelf4

The WDF_PTR_GET_OFFSET macro definition does not parenthesize its arguments correctly, leading to unexpected operator grouping in expansions. E.g., WDF_PTR_GET_OFFSET(p, q + 1) expands to (size_t) ((((PUCHAR) q) + 1 - ((PUCHAR) p)).

Proposed fix:

diff --git a/src/publicinc/wdf/kmdf/1.33/wdfcore.h b/src/publicinc/wdf/kmdf/1.33/wdfcore.h
index 06993eb..5597cc3 100644
--- a/src/publicinc/wdf/kmdf/1.33/wdfcore.h
+++ b/src/publicinc/wdf/kmdf/1.33/wdfcore.h
@@ -145,7 +145,7 @@ WDF_ALIGN_SIZE_UP(
         WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, PVOID)
 
 #define WDF_PTR_GET_OFFSET(_base, _addr) \
-        (size_t) (((PUCHAR) _addr) - ((PUCHAR) _base))
+        ((size_t) ((PUCHAR) (_addr) - (PUCHAR) (_base)))
 
 #if (OSVER(NTDDI_VERSION) == NTDDI_WIN2K)
 //

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions