Skip to content
  • Cheng Shao's avatar
    83341bbc
    rts: use __builtin_offsetof to implement STG_FIELD_OFFSET · 83341bbc
    Cheng Shao authored and Ben Gamari's avatar Ben Gamari committed
    This patch fixes the STG_FIELD_OFFSET macro definition by using
    __builtin_offsetof, which is what gcc/clang uses to implement offsetof
    in standard C. The previous definition that uses NULL pointer involves
    subtle undefined behavior in C and thus reported by
    UndefinedBehaviorSanitizer as well:
    
    ```
    rts/Capability.h:243:58: runtime error: member access within null pointer of type 'Capability' (aka 'struct Capability_')
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Capability.h:243:58
    ```
    83341bbc
    rts: use __builtin_offsetof to implement STG_FIELD_OFFSET
    Cheng Shao authored and Ben Gamari's avatar Ben Gamari committed
    This patch fixes the STG_FIELD_OFFSET macro definition by using
    __builtin_offsetof, which is what gcc/clang uses to implement offsetof
    in standard C. The previous definition that uses NULL pointer involves
    subtle undefined behavior in C and thus reported by
    UndefinedBehaviorSanitizer as well:
    
    ```
    rts/Capability.h:243:58: runtime error: member access within null pointer of type 'Capability' (aka 'struct Capability_')
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Capability.h:243:58
    ```
Loading