]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Skip an assert for posix_memalign if size==0. 17814/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Oct 2024 02:17:22 +0000 (20:17 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Oct 2024 02:17:22 +0000 (20:17 -0600)
POSIX says that the returned pointer can be a nullptr if the size requested is
zero. So skip the assertion if size==0.

source/base/utilities.cc

index 4485574b3368a4b8405c78fb0a3d7cfd7a68a6e5..c193f201f7ef246b67b04a10db3c97d25b0458b0 100644 (file)
@@ -1047,7 +1047,8 @@ namespace Utilities
       const int ierr = ::posix_memalign(memptr, alignment, size);
 
       AssertThrow(ierr == 0, ExcOutOfMemory(size));
-      AssertThrow(*memptr != nullptr, ExcOutOfMemory(size));
+      if (size > 0)
+        AssertThrow(*memptr != nullptr, ExcOutOfMemory(size));
 #else
       // Windows does not appear to have posix_memalign. just use the
       // regular malloc in that case

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.