@@ -44,21 +44,21 @@ Create the example:
4444 ``` cpp
4545 #include < stdio.h>
4646 #include < stdlib.h>
47-
47+
4848 void BadFunction (int * pointer)
4949 {
5050 free(pointer);
5151 free(pointer); // double-free!
5252 }
53-
53+
5454 int main(int argc, const char *argv[])
5555 {
5656 int *pointer = static_cast<int *>(malloc(4));
5757 BadFunction(pointer);
58-
58+
5959 // Normally we'd crash before this, but with COE we can see heap-use-after-free error as well
6060 printf("\n\n******* Pointer value: %d\n", *pointer);
61-
61+
6262 return 1;
6363 }
6464 ```
@@ -181,24 +181,24 @@ Create the example:
1811811 . In that directory, create a source file, for example, ` coe.cpp ` , and paste the following code:
182182
183183 ``` cpp
184- #include < stdlib.h>
185-
184+ #include < stdlib.h>
185+
186186 char * func (char* buf, size_t sz)
187- {
188- char* local = (char* )malloc(sz);
189- for (auto ii = 0; ii <= sz; ii++) // bad loop exit test
187+ {
188+ char* local = (char* )malloc(sz);
189+ for (auto ii = 0; ii <= sz; ii++) // bad loop exit test
190190 {
191- local[ ii] = ~ buf[ ii] ; // Two memory safety errors
191+ local[ ii] = ~ buf[ ii] ; // Two memory safety errors
192192 }
193-
194- return local;
195- }
196-
197- char buffer[ 10] = {0,1,2,3,4,5,6,7,8,9};
198-
193+
194+ return local;
195+ }
196+
197+ char buffer[10] = {0,1,2,3,4,5,6,7,8,9};
198+
199199 int main()
200- {
201- char* inverted_buf= func(buffer, 10);
200+ {
201+ char* inverted_buf= func(buffer, 10);
202202 }
203203 ```
204204
0 commit comments