Previous slide
Next slide
Toggle fullscreen
Open presenter view
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Allocate Cube
c
for
CreateCube
.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Deallocate stack memory of
CreateCube
and return address of
c
.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Allocate pointer
c
for
main
and store the returned value. Notice that the stack memory of
CreateCube
is
overwritten
.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Allocate stack memory for
getVolume
and calculate volume using the width of
c
. Since the width of
c
is
corrupted
, the volume is also
incorrect
.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Deallocate memory of
getVolume
. Allocate
r
for
main
to store the return value of
getVolume
.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Allocate stack memory for
getSurfaceArea
and calculate surface area using the width of
c
. Similar to
getVolume
, the surface area calculated will be incorrect.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Deallocate memory of
getSurfaceArea
. Allocate
v
for main to store the return value of
getSurfaceArea
.
Source:
https://courses.engr.illinois.edu/cs225/fa2022/resources/stack-heap/
Deallocate the stack memory of
main
and return
0