Integer overflow in globalIDSet
In the Alu3DGridGlobalIdSet
the entity IDs are created in the createId()
function, where an ID is a 3-tuple (macroKey, nChilds, codimLevel)
. The value nChilds
thereby is calculated by the formula:
int childOffSet = (dim == 2) ? 4 : ((cd == 1) && (elType == hexa)) ? 16 : 8;
int newChild = ((creatorId.codim()+1) * creatorId.nChild() * childOffSet ) + nChild
This newChild
value can grow quite fast, e.g. in 2d an integer overflow happens already at around 10 grid levels.
I propose to modify the datatype of thenChilds
value to something larger than int
, e.g. long
or long long
, or even a biginteger type. This would increase the datasize of a global ID, so maybe this should be made either a template parameter or a compile flag.
An alternative or independent extension would be to check for integer overflow more carefully. The test newChild >= 0
fails if the overflow produces a positive integer (this happens in real life code).