Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ Rank: minor
Fix MSVC compilation of matrix slice conversion operators by fully
qualifying their dependent return types.

[ENTRY]
Module: kernel
What: bug
Rank: minor
Issue: 205
Thanks: intractabilis
[DESCRIPTION]
Fix construction of argument arrays from empty `std::vector` instances
so zero-length copies do not take the address of a nonexistent first
element.

[ENTRY]
Module: float
What: bug
Expand Down
3 changes: 2 additions & 1 deletion gecode/kernel/data/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,8 @@ namespace Gecode {
ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
: n(static_cast<int>(aa.size())),
capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
heap.copy<T>(a,&aa[0],n);
if (n > 0)
heap.copy<T>(a,aa.data(),n);
Comment on lines +1560 to +1561

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: aa.data() is fine to call on an empty std::vector (might or might not return nullptr). do we need the if (n > 0) then?

}

template<class T>
Expand Down
28 changes: 28 additions & 0 deletions test/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <gecode/kernel.hh>
#include <gecode/int.hh>

#include <vector>

#include "test/test.hh"

/// Check the test result and handle failed test
Expand Down Expand Up @@ -190,6 +192,32 @@ namespace Test {
}
};

/// Test name prefix for vector construction
static const std::string vectorPrefix("Array::Vector::");

/// %Class for testing construction from empty vectors
class EmptyVector : public Test::Base {
public:
/// Initialize test
EmptyVector(void) : Test::Base(vectorPrefix + "Empty") {}
/// Perform actual tests
bool run(void) {
std::vector<int> ints;
Gecode::IntArgs ia(ints);
if (ia.size() != 0)
return false;

std::vector<Gecode::IntVar> intVars;
Gecode::IntVarArgs iva(intVars);
if (iva.size() != 0)
return false;

std::vector<Gecode::BoolVar> boolVars;
Gecode::BoolVarArgs bva(boolVars);
return bva.size() == 0;
}
} emptyVectorTest;

/// %Class for testing the VarArray iterator
class VarArrayIterator : public Iterator {
protected:
Expand Down