mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Fix memory address in self-referential struct example
This commit is contained in:
committed by
GitHub
parent
27ac0e1acc
commit
cd8e139ab0
@@ -523,9 +523,9 @@ The internal pointer of our self-referential struct leads to a fundamental probl
|
||||
|
||||
The `array` field starts at address 0x10014 and the `element` field at address 0x10020. It points to address 0x1001c because the last array element lives at this address. At this point, everything is still fine. However, an issue occurs when we move this struct to a different memory address:
|
||||
|
||||

|
||||

|
||||
|
||||
We moved the struct a bit so that it starts at address `0x10024` now. This could for example happen when we pass the struct as a function argument or assign it to a different stack variable. The problem is that the `element` field still points to address `0x1001c` even though the last `array` element now lives at address `0x1002a`. Thus, the pointer is dangling with the result that undefined behavior occurs on the next `poll` call.
|
||||
We moved the struct a bit so that it starts at address `0x10024` now. This could for example happen when we pass the struct as a function argument or assign it to a different stack variable. The problem is that the `element` field still points to address `0x1001c` even though the last `array` element now lives at address `0x1002c`. Thus, the pointer is dangling with the result that undefined behavior occurs on the next `poll` call.
|
||||
|
||||
#### Possible Solutions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user