Static Code Analysis result Update (#2624)

BUG="static code analysis result update"

Build test was done with the command below
  make -f tensorflow/lite/micro/tools/make/Makefile test

There will be an additional pull request later related to static code analysis
This commit is contained in:
Johnney Jung 2024-07-17 02:52:18 +09:00 committed by GitHub
parent ff5c090eca
commit 7a0249686f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 6 deletions

View file

@ -129,7 +129,8 @@ class AllocationInfoBuilder {
const tflite::Model* model_ = nullptr;
INonPersistentBufferAllocator* non_persistent_allocator_ = nullptr;
GraphAllocationInfo info_;
GraphAllocationInfo info_ =
{}; // Prevents problems caused by accessing uninitialized memory.
int allocation_scope_count_ = 0;
};

View file

@ -322,7 +322,9 @@ class MicroAllocator {
IPersistentBufferAllocator* persistent_buffer_allocator_;
// Allocator used to allocate persistent builtin data.
TfLiteBridgeBuiltinDataAllocator* builtin_data_allocator_;
TfLiteBridgeBuiltinDataAllocator* builtin_data_allocator_ =
nullptr; // Initialized as nullptr to prevent any possible issues related
// to accessing uninitialized memory.
// Activation buffer memory planner.
MicroMemoryPlanner* memory_planner_;

View file

@ -106,7 +106,9 @@ class MicroInterpreterGraph : public MicroGraph {
int current_subgraph_index_;
uint32_t current_operator_index_;
MicroResourceVariables* resource_variables_;
const flatbuffers::Vector<flatbuffers::Offset<SubGraph>>* subgraphs_;
const flatbuffers::Vector<flatbuffers::Offset<SubGraph>>* subgraphs_ =
nullptr; // Initialized as nullptr to prevent any possible issues
// related to accessing uninitialized memory.
TF_LITE_REMOVE_VIRTUAL_DELETE
};

View file

@ -27,8 +27,11 @@ uint32_t ticks_per_second();
uint32_t GetCurrentTimeTicks();
inline uint32_t TicksToMs(int32_t ticks) {
uint32_t _ticks_per_second = ticks_per_second();
_ticks_per_second =
_ticks_per_second > 0 ? _ticks_per_second : 1; // zero divide prevention
return static_cast<uint32_t>(1000.0f * static_cast<float>(ticks) /
static_cast<float>(ticks_per_second()));
static_cast<float>(_ticks_per_second));
}
} // namespace tflite

View file

@ -78,9 +78,14 @@ RecordedAllocation RecordingMicroAllocator::GetRecordedAllocation(
return recorded_node_and_registration_array_data_;
case RecordedAllocationType::kOpData:
return recorded_op_data_;
// the function MicroPrintf was never reached outside the switch, because
// each case has a return. As the intention of the MicroPrintf is to be
// called when no matching case is found, a default case was added to
// contemplate an invalid allocation type
default:
MicroPrintf("Invalid allocation type supplied: %d", allocation_type);
return RecordedAllocation();
}
MicroPrintf("Invalid allocation type supplied: %d", allocation_type);
return RecordedAllocation();
}
const RecordingSingleArenaBufferAllocator*