소스 검색

test for failed "new" properly

Ian Goldberg 1 년 전
부모
커밋
88ec550dee
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      Enclave/sort.cpp

+ 5 - 3
Enclave/sort.cpp

@@ -27,11 +27,13 @@ static EvalPlans precomp_eps;
 
 void sort_precompute(uint32_t N)
 {
-    uint32_t *random_permutation = new uint32_t[N];
-    if (!random_permutation) {
+    uint32_t *random_permutation = NULL;
+    try {
+        random_permutation = new uint32_t[N];
+    } catch (std::bad_alloc&) {
         printf("Allocating memory failed in sort_precompute\n");
+        assert(false);
     }
-    assert(random_permutation);
     for (uint32_t i=0;i<N;++i) {
         random_permutation[i] = i;
     }