Skip to content
  • Cheng Shao's avatar
    05c4fafb
    rts: use __builtin_offsetof to implement STG_FIELD_OFFSET · 05c4fafb
    Cheng Shao authored and Marge Bot's avatar Marge Bot 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
    ```
    05c4fafb
    rts: use __builtin_offsetof to implement STG_FIELD_OFFSET
    Cheng Shao authored and Marge Bot's avatar Marge Bot 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