Since each connection is handled independently by a

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: id bufoverflow() { char buf[64]; gets(buf); /* here is the stack buffer overflow bug */ return; } 10.11.4 Assuming that Pointers and the Objects they Point to Are the Same Size One common mistake is to assume that pointers to objects are the same size as the objects they point to: 1 2 3 4 5 6 7 8 9 10 /* Create an nxm array */ int **makeArray1(int n, int m) { int i; int **A = (int **)Malloc(n * sizeof(int)); for (i = 0; i < n; i++) A[i] = (int *)Malloc(m * sizeof(int)); return A; } The intent here is to create an array of Ò pointers, each of which points to an array of Ñ ints. However, because the programmer has written sizeof(int) instead of sizeof(int *) in line 5, the code 10.11. COMMON MEMORY-RELATED BUGS IN C PROGRAMS 553 actually creates an array of ints. This code will run fine on machines where ints and pointers to ints are the same size. But if we run this code on a machine like the Alpha, where a pointer is larger than an int, then the loop in lines 7 and 8 will write past the end o...
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