1 570 chapter 11 concurrent programming with threads

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: f the A array. Since one of these words will likely be the boundary tag footer of the allocated block, we may not discover the error until we free the block much later in the program, at which point the coalescing code in the allocator will fail dramatically and for no apparent reason. This is an insidious example of the kind of “action at a distance” that is so typical of memory-related programming bugs. 10.11.5 Making Off-by-one Errors Off-by-one errors are another common source of overwriting bugs: 1 2 3 4 5 6 7 8 9 10 /* Create an nxm array */ int **makeArray2(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; } This is another version of the program in the previous section. Here we have created an Ò-element array of pointers in line 5, but then tried to initialize Ò · ½ of its elements in lines 7 and 8, in the process overwriting some memory that follows the A array. 10.11.6 Referencing a Pointer Inst...
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