Add nullptr checks
Change-Id: Ie76db24dec03a6b45c64070d89a83805397d2f1f
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp
index a888928..1768271 100644
--- a/driver_library/src/ethosu.cpp
+++ b/driver_library/src/ethosu.cpp
@@ -50,6 +50,10 @@
size_t getShapeSize(const flatbuffers::Vector<int32_t> *shape) {
size_t size = 1;
+ if (shape == nullptr) {
+ throw EthosU::Exception("getShapeSize(): nullptr arg");
+ }
+
for (auto it = shape->begin(); it != shape->end(); ++it) {
size *= *it;
}
@@ -74,6 +78,10 @@
vector<size_t> getSubGraphDims(const tflite::SubGraph *subgraph, const flatbuffers::Vector<int32_t> *tensorMap) {
vector<size_t> dims;
+ if (subgraph == nullptr || tensorMap == nullptr) {
+ throw EthosU::Exception("getSubGraphDims(): nullptr arg(s)");
+ }
+
for (auto index = tensorMap->begin(); index != tensorMap->end(); ++index) {
auto tensor = subgraph->tensors()->Get(*index);
size_t size = getShapeSize(tensor->shape());
@@ -190,6 +198,10 @@
// Create model handle
const tflite::Model *model = tflite::GetModel(reinterpret_cast<void *>(buffer->data()));
+ if (model->subgraphs() == nullptr) {
+ throw EthosU::Exception("Failed to get subgraphs: nullptr");
+ }
+
// Get input dimensions for first subgraph
auto *subgraph = *model->subgraphs()->begin();
ifmDims = getSubGraphDims(subgraph, subgraph->inputs());