Gecode / gecode

Generic Constraint Development Environment
https://www.gecode.org
Other
283 stars 76 forks source link

clang-10: warning: array index 1 is past the end of the array #95

Closed yurivict closed 4 years ago

yurivict commented 4 years ago

This warning appears to indicate a serious problem:

In file included from /usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/set/cardinality.cpp:38:
In file included from /usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/set.hh:43:
In file included from /usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel.hh:150:
/usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel/core.hpp:4584:7: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
      x->u.idx[1] = u.idx[1];
      ^        ~
/usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel/core.hpp:4659:49: note: in instantiation of member function 'Gecode::VarImp<Gecode::Int::BoolVarImpConf>::update' requested here
      VarImp<VIC>* n = x->next(); x->forward()->update(x,sub); x = n;
                                                ^
/usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel/var-imp.hpp:487:50: note: in instantiation of member function 'Gecode::VarImp<Gecode::Int::BoolVarImpConf>::update' requested here
    Gecode::VarImp<Gecode::Int::BoolVarImpConf>::update(*this,sub);
                                                 ^
/usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel/core.hpp:273:7: note: array 'idx' declared here
      unsigned int idx[pc_max+1];
      ^
/usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel/core.hpp:4584:21: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
      x->u.idx[1] = u.idx[1];
                    ^     ~
/usr/ports/devel/gecode/work/gecode-release-6.2.0/gecode/kernel/core.hpp:273:7: note: array 'idx' declared here
      unsigned int idx[pc_max+1];
      ^
zayenz commented 4 years ago

It does seem that way, but is not actually a problem: the warning is a false positive. The access is guarded by a check that is only true if the array has at least one value.

See https://github.com/Gecode/gecode/commit/bb1efcd8c4bf5d8d6c079a1b7704c51ea958bf06 for the fix that supresses the warning in question.