ralna / spral

Sparse Parallel Robust Algorithms Library
https://ralna.github.io/spral/
Other
102 stars 27 forks source link

Fix uninitialised ptr compiler warning #190

Closed jfowkes closed 5 months ago

jfowkes commented 5 months ago

As reported by @nimgould compilers currently raise a warning for this section of BuddyAllocator.hxx:

   void* allocate(std::size_t sz) {
      // Try allocating in existing pages
      spral::omp::AcquiredLock scopeLock(lock_);
      void* ptr;
      for(auto& page: pages_) {
         ptr = page.allocate(sz);
         if(ptr) break; // allocation suceeded
      }
      if(!ptr) {
         // Failed to alloc on existing page: make a bigger page and use it

that the pointer may be used uninitialised:

warning: ‘ptr’ may be used uninitialized in this function
|       if(!ptr) {

This PR explicitly initialises the pointer to nullptr rather than expecting the compiler to do this.

jfowkes commented 5 months ago

Agreed thanks @mjacobse!