324_Book

543 733 there is nothing very tricky here but the

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 162] Understanding structure layout and alignment is very important for understanding how much storage different data structures require and for understanding the code generated by the compiler for accessing structures. This problem lets you work out the details of some example structures. A. struct P1 { int i; char c; int j; char d; }; i 0 c 4 j 8 d 12 Total 16 Alignment 4 B. struct P2 { int i; char c; char d; int j; }; i 0 c 4 d 5 j 8 Total 12 Alignment 4 C. struct P3 { short w[3]; char c[3] }; w 0 c 6 Total 10 Alignment 2 D. struct P4 { short w[3]; char *c[3] }; w 0 c 8 Total 20 Alignment 4 E. struct P3 { struct P1 a[2]; struct P2 *p }; a 0 Problem 3.24 Solution: [Pg. 170] This problem covers a wide range of topics: stack frames, string representations, ASCII code, and byte ordering. It demonstrates the dangers of out-of-bounds memory references and the basic ideas behind buffer overﬂow. A. Stack at line 7. p 32 Total 36 Alignment 4 712 +-------------+ | 08 04 86 43 | +-------------+ | bf ff fc 94 | +-------------+ | | +-------------+ | | +-------------+ | | +-------------+ | | +-------------+ | 00 00 00 01 | +-------------+ | 00 00 00 02 | +-------------+ APPENDIX B. SOLUTIONS TO PRACTICE PROBLEMS Return Address Saved %ebp <-- %ebp buf[4-7] buf[0-3] Saved %esi Saved %ebx B. Stack after line 10 (showing only words that are modiﬁed). +-------------+ | 08 04 86 00 | +-----...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online