@@ -228,21 +228,26 @@ __tysan_check(void *addr, int size, tysan_type_descriptor *td, int flags) {
228
228
OldTDPtr -= i;
229
229
OldTD = *OldTDPtr;
230
230
231
- // When shadow memory is set for global objects, the entire object is tagged
232
- // with the struct type This means that when you access a member variable,
233
- // tysan reads that as you accessing a struct midway through, with 'i' being
234
- // the offset Therefore, if you are accessing a struct, we need to find the
235
- // member type. We can go through the members of the struct type and see if
236
- // there is a member at the offset you are accessing the struct by. If there
237
- // is indeed a member starting at offset 'i' in the struct, we should check
238
- // aliasing legality with that type. If there isn't, we run alias checking
239
- // on the struct which will give us the correct error.
240
231
tysan_type_descriptor *AccessedType = OldTD;
241
- if (OldTD->Tag == TYSAN_STRUCT_TD) {
242
- for (int j = 0 ; j < OldTD->Struct .MemberCount ; ++j) {
243
- if (OldTD->Struct .Members [j].Offset == i) {
244
- AccessedType = OldTD->Struct .Members [j].Type ;
245
- break ;
232
+
233
+ // Only check if we are accessing members if the type exists
234
+ if (OldTD != nullptr ) {
235
+ // When shadow memory is set for global objects, the entire object is
236
+ // tagged with the struct type This means that when you access a member
237
+ // variable, tysan reads that as you accessing a struct midway through,
238
+ // with 'i' being the offset Therefore, if you are accessing a struct, we
239
+ // need to find the member type. We can go through the members of the
240
+ // struct type and see if there is a member at the offset you are
241
+ // accessing the struct by. If there is indeed a member starting at offset
242
+ // 'i' in the struct, we should check aliasing legality with that type. If
243
+ // there isn't, we run alias checking on the struct which will give us the
244
+ // correct error.
245
+ if (OldTD->Tag == TYSAN_STRUCT_TD) {
246
+ for (int j = 0 ; j < OldTD->Struct .MemberCount ; ++j) {
247
+ if (OldTD->Struct .Members [j].Offset == i) {
248
+ AccessedType = OldTD->Struct .Members [j].Type ;
249
+ break ;
250
+ }
246
251
}
247
252
}
248
253
}
0 commit comments