aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Svärd <jonny.svaerd@arm.com>2021-04-12 15:56:44 +0200
committerJonny Svärd <jonny.svaerd@arm.com>2021-04-12 16:00:07 +0200
commit2c01713dbeba8446b135ef19fc443b6abe098210 (patch)
tree06e53eb8f70e08a985fb7419849a503cf6bcbd3b
parent4e5e056efb0861ad05cb92914aee5ed23f86660e (diff)
downloadethos-u-linux-driver-stack-2c01713dbeba8446b135ef19fc443b6abe098210.tar.gz
Add nullptr checks21.05-rc321.05-rc221.05
Change-Id: Ie76db24dec03a6b45c64070d89a83805397d2f1f
-rw-r--r--driver_library/src/ethosu.cpp12
1 files changed, 12 insertions, 0 deletions
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 @@ int eioctl(int fd, unsigned long cmd, void *data = nullptr) {
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 @@ size_t getTensorTypeSize(const enum tflite::TensorType type) {
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 @@ Network::Network(Device &device, shared_ptr<Buffer> &buffer) : fd(-1), buffer(bu
// 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());