<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/91144>91144</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libunwind] Undefined behavior pointer arithmetic with null pointer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          avdv
      </td>
    </tr>
</table>

<pre>
    I am using libunwind and when compiling my program with `-fsanitize=undefined` I get several reports of undefined behavior:
```
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:286:17: runtime error: applying non-zero offset 156 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:286:17 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:286:17: runtime error: member access within null pointer of type 'unwind_info_section_header_index_entry'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:286:17 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:291:17: runtime error: member access within null pointer of type 'unwind_info_section_header_index_entry'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:291:17 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:296:17: runtime error: member access within null pointer of type 'unwind_info_section_header_index_entry'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:296:17 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:296:17: runtime error: applying non-zero offset 12 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:296:17 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:337:17: runtime error: applying non-zero offset 2040 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:337:17 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:343:9: runtime error: applying non-zero offset 160 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:343:9 in 
native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:291:17: runtime error: applying non-zero offset 228 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior native/native-code-nativelib_native0.4_3-0.4.17-2/scala-native/platform/posix/libunwind/UnwindCursor.hpp:291:17 in 
```
Each of these is using the `arrayoffsetof` macro, which is defined like this:
```
#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV01v4zYQ_TXUZSCBor4POjjrGtjDXrrIoSeDkkYWW4oUSMpe59cXlGynaZsC6R4SGAEEeGRyRjPvDTF83FpxUIg1yR5Itg347AZtan7sjkGju3P9FfgIsxXqAFI0szoJ1QFXHZwGVNDqcRLSL45nmIw-GD7CSbgBSE7D3nIlnHhCkmxn1WEvFHYkp_AVDujA4hENl2Bw0sZZ0D3cdkGDAz8KbUiyIXRL6Ibk9PIsr4o7cUTCdqsRtrrDcLWlaParRaN0n4Q0SqO4CBlhO9tyycOb7yS567UZvamt-EHY7lYkYbvHxfgyG6tNNEwTSTaszEmyiQuSbMDMyokRAY1Z8gQ-TfLswVBahU9oNOi-t-ggznJwGtQsJUxaKIdmreL747dvm19_886P19IfLpV_v4C3hL4BE16BgXdGAISCj0vFiGODBnjborVLRwr1An_fbe48IRBWrF_ZC9XrvcXWCa32A_IOzV6oDn_sUTlzJqz4JO2nE6niT9LeiNUHIO3zpL0Vq49N2uuTit3PoPooTCRJ8T-YYDSld8PFFYL35yJNSLKp3ngo8jtiYgXg3Yn4z4vA64eClXfDxD_H-98kzi-8HZbhOaBFEPYiw9yAXl1xY_h5hUX3XlSNvDWasC9wGkQ7-P1XLSXFHwhuEPY1MUVYsu6Fl1FZ6Qe3j7lMZ2_0AmVHWAWElYSVVjzh3hFWLa_5-udl2m8Iq6hfyh5W92wbXd3982-ZBF2ddFVS8QDruIjTKmUFS4OhLtqyKDHuG9q3TZHRpu-qtscua_My7psuEDWjLKUZzRjNyjSNupQVTV_ErOiqvI17klIcuZCRlMcx0uYQCGtnrKs4TtNA8galXWQwYwpPsCwSxrwqNrX3CZv5YElKpbDOPkdxwslFPz_znW2fu_CmZG_3IW6EG0Z0ol2l8l-7OZiNrAfnpoUrtiNsdxBumJuo1b63_FcvP-Fk9O_YOsJ2S66WsN1Sy58BAAD__w6tVLo">