Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
* Fix potential out of bounds read in AspifTextOutput::atomArity.
* Fix potential integer overflow in matchDomHeuPred and "Test alarm".
* Fix potential invalid memcpy call in TheoryAtom construction -
  pointers passed to std::memcpy must not be null even if the size
  to copy is 0.
  • Loading branch information
BenKaufmann committed Sep 20, 2024
1 parent 2ec11ab commit 4434358
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/aspif_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ struct AspifTextOutput::Data {
for (StringSpan ignore;;) {
POTASSCO_REQUIRE(matchAtomArg(args, ignore), "invalid empty argument in name");
++arity;
if (*args++ == ')') break;
if (*args != ',') break;
++args;
}
POTASSCO_REQUIRE(!*args, "invalid character in name");
POTASSCO_REQUIRE(*args == ')' && !*++args, "invalid character in name");
return arity;
}

Expand Down
2 changes: 1 addition & 1 deletion src/match_basic_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ int matchDomHeuPred(const char*& in, StringSpan& atom, Heuristic_t& type, int& b
if (!matchAtomArg(in, atom) || !match(in, ",")) { return -1; }
if (!match(in, type) || !match(in, ",")) { return -2; }
if (!match(in, bias)) { return -3; }
prio = static_cast<unsigned>(bias < 0 ? -bias : bias);
prio = bias < 0 ? static_cast<unsigned>(~bias) + 1u : static_cast<unsigned>(bias);
if (!match(in, ",")) { return match(in, ")") ? 1 : -3; }
if (!match(in, p) || p < 0) { return -4; }
prio = static_cast<unsigned>(p);
Expand Down
2 changes: 1 addition & 1 deletion src/theory_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ TheoryAtom::TheoryAtom(Id_t a, Id_t term, const IdSpan& args, Id_t* op, Id_t* rh
, guard_(op != 0)
, termId_(term)
, nTerms_(static_cast<uint32_t>(Potassco::size(args))) {
std::memcpy(term_, Potassco::begin(args), nTerms_ * sizeof(Id_t));
nTerms_ == 0 || std::memcpy(term_, Potassco::begin(args), nTerms_ * sizeof(Id_t));
if (op) {
term_[nTerms_] = *op;
term_[nTerms_ + 1] = *rhs;
Expand Down
6 changes: 3 additions & 3 deletions tests/test_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ TEST_CASE("Test alarm", "[app]") {
struct TimedApp : MyApp {
TimedApp() : stop(0) {}
void run() {
int i = 0;
unsigned i = 0;
while (!stop) { ++i; }
setExitCode(i);
setExitCode(1 + stop);
}
virtual bool onSignal(int) {
stop = 1;
Expand All @@ -102,7 +102,7 @@ TEST_CASE("Test alarm", "[app]") {
TimedApp app;
char* argv[] = {(char*)"app", (char*)"--time-limit=1", 0};
int argc = 2;
app.main(argc, argv);
REQUIRE(app.main(argc, argv) == 2);
REQUIRE(app.stop == 1);
}
}}}

0 comments on commit 4434358

Please sign in to comment.