void myTest(void) { char* str1 = utstrdup("apple"); printf("%s\n", str1); char* str2 = utstrdup(""); printf("%s\n", str2); uint32_t str1_len = utstrlen(str1); printf("%d\n", str1_len); uint32_t str2_len = utstrlen(str2); printf("%d\n", str2_len); char* str3 = utstrcat(str1, " pickle"); printf("%s\n", str3); char* str4 = utstrcat(str1, ""); printf("%s\n", str4); utstrcpy(str1, "pie"); printf("%s\n", str1); utstrcpy(str1, "big old massive hunk of yummy pie"); printf("%s\n", str1); utstrcpy(str1, ""); printf("%s\n", str1); utstrfree(str2); char* str5 = utstrrealloc(str1, 20); printf("%s\n", str5); utstrcpy(str5, "big old massive hunk of yummy pie"); printf("%s\n", str5); str5 = utstrrealloc(str5, 0); printf("%s\n", str5); utstrcpy(str5, "big old massive hunk of yummy pie"); printf("%s\n", str5); //str4 = utstrrealloc(str5, -1); //should crash program printf("%s\n", str4); }
void testStage4(void) { char p[20]; if (! isSaneHeap()) { printf("oh goodness! you've corrupted the heap, naughty naughty\n"); return; } if (! isEmptyHeap()) { printf("Uh Oh! you have a memory leak somewhere, better find it\n"); return; } /* if we reach this point, the heap is OK */ printf("woo HOO! the heap is OK, test 4 looks good so far, now we're going to crash...\n"); /* each of the following lines should crash the program (an assert should fail) * try each of them in turn to make sure you're catching the obvious mistakes * just uncomment the line and see what happens (it should crash) */ printf("crashing with utstrlen\n\n\n"); utstrlen("Hello World"); printf("crashing with utstrcpy\n\n\n"); utstrcpy(p, "Hello World"); printf("crashing with utstrcat\n\n\n"); utstrcat(p, "Hello World"); printf("crashing with utstrfree\n\n\n"); utstrfree((char *)malloc(20)); printf("crashing with utstrrealloc\n\n\n"); utstrrealloc((char *)malloc(20), 40); }