new_array<int>(LONG_MAX) does not raise exception

Issue #59 resolved
Nenad Vukicevic created an issue

I tried to write a simple alloc test and raise std::bad_alloc exception. Something like this:

global_ptr<int> iptr = new_array<int>(LONG_MAX);

It did not raise exception and something actually got allocated. I tried to follow the code and it seems that this code in allocate.hpp:103 does not take into account that overflow might happen:

100       std::size_t size = sizeof(std::size_t);
101       size = (size + alignof(T)-1) & -alignof(T);
102       std::size_t offset = size;
103       size += n * sizeof(T);

I know that this is a cornet case.

And BTW if I do LONG_MAX-1024 I get some UPCXX assertion error.

Is there a way to extract GASNET shared memory size? Or I'll need to limit the size and play around it.

Comments (6)

  1. Nenad Vukicevic reporter

    I tried to allocate by using new_array() in the loop. It looks like I am running into some kind of assertion after allocating 128Mb. But no "bad_alloc" exception OR nullptr.

    Here is the code that expects nullptr:

      global_ptr<int> aptr;
      int cnt=1;
    
      aptr = new_array<int>(1024, std::nothrow);
      while (aptr != nullptr) {
        cnt++;
        aptr = new_array<int>(1024, std::nothrow);
        std::cout << cnt << "\n";
      }
    

    It get the following:

    UPC++ assertion failure on rank 0 [/eng/upc/dev/nenad/upcxx/src/upcxx/src/backend/gasnet/runtime.cpp:194]
    *** Caught a fatal signal: SIGABRT(6) on node 0/1
    
  2. Amir Kamil

    I fixed the first issue in 778ff6b. The second issue is an assert in src/backend/gasnet/runtime.cpp:

        UPCXX_ASSERT(p != nullptr);
    

    I'm going to defer that one to John, as I don't know the intent behind it.

  3. Log in to comment