From b7ab3ef61cdb9cd3dc084e7055c1a516b9434cce Mon Sep 17 00:00:00 2001 From: raabh Date: Sun, 30 Jul 2023 22:10:37 +0200 Subject: [PATCH] fixed an overflow error caused by choosing too small a type to store variables --- src/methods/nnf/NodeManager.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/methods/nnf/NodeManager.hpp b/src/methods/nnf/NodeManager.hpp index fdc90d27..2f79d2cb 100644 --- a/src/methods/nnf/NodeManager.hpp +++ b/src/methods/nnf/NodeManager.hpp @@ -252,8 +252,10 @@ class NodeManager { @param[in] nbVar, the number of variables in the problem. */ static NodeManager *makeNodeManager(unsigned nbVar) { - if (nbVar < (1 << 8)) return new NodeManagerTyped(); - if (nbVar < (1 << 16)) return new NodeManagerTyped(); + // One bit is reserved for the sign of the variable. + // Hence, with 8 bits we can store variables from -(2⁷-1) up to 2⁷-1. Same holds for 16 and 32 bits. + if (nbVar < (1 << 7)) return new NodeManagerTyped(); + if (nbVar < (1 << 15)) return new NodeManagerTyped(); return new NodeManagerTyped(); } // makeNodeManager