iOS often mixes C code, while in C, reading and writing to memory is a very frequent operation.
Where memory is out-of-bounds read and write
unsigned char* p = (unsigned char*) malloc (+); unsigned char c = * (p+100); Free (p);
is a very easy mistake, and in most cases this code will not expose the problem.
If you write memory out of bounds, such as:
unsigned char* p = (unsigned char*) malloc (10); * (p+100) = ' C '; Free (p);
Like what:
unsigned char* p = (unsigned char*) malloc (10); uiviewcontroller* VC =[uiviewcontroller new]; * (p+100) = ' C '; [VC view]; Free (p);
Because violence changes the contents of VC objects, and then the VC objects to operate, there will be an exception occurs.
In reality, such bugs are often hidden deep. Because of the memory that is modified over the bounds, it may belong to an unused memory, or to an object that is infrequently accessed. For testers, the application will become unstable, under any page, it is possible to hang, and there is no necessary connection between them. Like burying a mine on the road, anyone could have stepped on the Thunder.
Fortunately, Xcode provides a way for us to correct this kind of bug.
1, at run time, add the following options:
This method applies only to simulators.
If you are debugging on a real machine, you will not find a mirror-phase error.
2, when the above memory read and write code, will directly navigate to the code of the problem.
Resolve memory out-of-bounds access issues on iOS