Skip to content

Commit

Permalink
Silence Minisat's use of realloc on non-POD and fix and use its xrealloc
Browse files Browse the repository at this point in the history
This was a new GCC 8 warning; testing on errno == ENOMEM with && opened the door
for non-compliant implementations to fail to allocate without capacity()
failing.
  • Loading branch information
tautschnig committed Jun 5, 2018
1 parent 3082d9d commit 4f3c102
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions scripts/minisat-2.2.1-patch
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,39 @@ index 9cbbc51..27b9700 100644
#include <fpu_control.h>
#endif

diff --git a/minisat/mtl/Vec.h b/minisat/mtl/Vec.h
--- a/minisat/mtl/Vec.h
+++ b/minisat/mtl/Vec.h
@@ -96,8 +96,10 @@
void vec<T>::capacity(int min_cap) {
if (cap >= min_cap) return;
int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2
- if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM))
- throw OutOfMemoryException();
+ if (add > INT_MAX - cap)
+ throw OutOfMemoryException();
+
+ data = (T*)xrealloc(data, (cap += add) * sizeof(T));
}


diff --git a/minisat/mtl/XAlloc.h b/minisat/mtl/XAlloc.h
--- a/minisat/mtl/XAlloc.h
+++ b/minisat/mtl/XAlloc.h
@@ -21,7 +21,6 @@
#ifndef Minisat_XAlloc_h
#define Minisat_XAlloc_h

-#include <errno.h>
#include <stdlib.h>

namespace Minisat {
@@ -33,7 +32,7 @@
static inline void* xrealloc(void *ptr, size_t size)
{
void* mem = realloc(ptr, size);
- if (mem == NULL && errno == ENOMEM){
+ if (mem == NULL){
throw OutOfMemoryException();
}else
return mem;

0 comments on commit 4f3c102

Please sign in to comment.