/*
* -*- c++ -*-
*
- * (C) Copyright IBM Corp. and others 2013 - All Rights Reserved
+ * (C) Copyright IBM Corp. and others 2015 - All Rights Reserved
*
* Range checking
*
return fLength;
}
+ /**
+ * Throw an error if size*count overflows
+ */
+ size_t verifyLength(size_t offset, size_t size, le_uint32 count, LEErrorCode &success) {
+ if(count!=0 && size>LE_UINT32_MAX/count) {
+ LE_DEBUG_TR3("verifyLength failed size=%u, count=%u", size, count);
+ success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
+ return 0;
+ }
+ return verifyLength(offset, size*count, success);
+ }
+
/**
* Change parent link to another
*/
if(count == LE_UNBOUNDED_ARRAY) { // not a known length
count = getLength()/LETableVarSizer<T>::getSize(); // fit to max size
}
- LETableReference::verifyLength(0, LETableVarSizer<T>::getSize()*count, success);
+ LETableReference::verifyLength(0, LETableVarSizer<T>::getSize(), fCount, success);
}
if(LE_FAILURE(success)) {
fCount=0;
if(count == LE_UNBOUNDED_ARRAY) { // not a known length
count = getLength()/LETableVarSizer<T>::getSize(); // fit to max size
}
- LETableReference::verifyLength(0, LETableVarSizer<T>::getSize()*count, success);
+ LETableReference::verifyLength(0, LETableVarSizer<T>::getSize(), fCount, success);
}
if(LE_FAILURE(success)) clear();
}
if(count == LE_UNBOUNDED_ARRAY) { // not a known length
count = getLength()/LETableVarSizer<T>::getSize(); // fit to max size
}
- LETableReference::verifyLength(0, LETableVarSizer<T>::getSize()*count, success);
+ LETableReference::verifyLength(0, LETableVarSizer<T>::getSize(), fCount, success);
}
if(LE_FAILURE(success)) clear();
}
const T *getAliasRAW() const { LE_DEBUG_TR("getAliasRAW<>"); return (const T*)fStart; }
const T& getObject(le_uint32 i, LEErrorCode &success) const {
- return *getAlias(i,success);
+ const T *ret = getAlias(i, success);
+ if (LE_FAILURE(success) || ret==NULL) {
+ return *(new T(0));
+ } else {
+ return *ret;
+ }
}
const T& operator()(le_uint32 i, LEErrorCode &success) const {