瀏覽代碼

Add test of calloc with overflow

Peter Limkilde Svendsen 6 年之前
父節點
當前提交
8b7453edf2
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      tests/stdlib/alloc.c

+ 4 - 0
tests/stdlib/alloc.c

@@ -18,6 +18,10 @@ int main(int argc, char ** argv) {
     }
     free(ptrc);
 
+    char * ptrco = (char *)calloc(SIZE_MAX, SIZE_MAX);
+    printf("calloc (overflowing) %p\n", ptrco);
+    free(ptrco); /* clean up correctly even if overflow is not handled */
+
     char * ptra = (char *)memalign(256, 256);
     printf("memalign %p\n", ptra);
     for(i = 0; i < 256; i++) {