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
diff --git a/tensorflow/lite/micro/micro_allocation_info.h b/tensorflow/lite/micro/micro_allocation_info.h index 688d04e..c0c7bd5 100644 --- a/tensorflow/lite/micro/micro_allocation_info.h +++ b/tensorflow/lite/micro/micro_allocation_info.h
@@ -129,7 +129,8 @@ 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; };
diff --git a/tensorflow/lite/micro/micro_allocator.h b/tensorflow/lite/micro/micro_allocator.h index 4eff167..0231722 100644 --- a/tensorflow/lite/micro/micro_allocator.h +++ b/tensorflow/lite/micro/micro_allocator.h
@@ -322,7 +322,9 @@ 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_;
diff --git a/tensorflow/lite/micro/micro_interpreter_graph.h b/tensorflow/lite/micro/micro_interpreter_graph.h index 7ae0794..5fc3b4c 100644 --- a/tensorflow/lite/micro/micro_interpreter_graph.h +++ b/tensorflow/lite/micro/micro_interpreter_graph.h
@@ -106,7 +106,9 @@ 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 };
diff --git a/tensorflow/lite/micro/micro_time.h b/tensorflow/lite/micro/micro_time.h index 7a8ab45..5e8ad11 100644 --- a/tensorflow/lite/micro/micro_time.h +++ b/tensorflow/lite/micro/micro_time.h
@@ -27,8 +27,11 @@ 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
diff --git a/tensorflow/lite/micro/recording_micro_allocator.cc b/tensorflow/lite/micro/recording_micro_allocator.cc index f41dba6..ee76196 100644 --- a/tensorflow/lite/micro/recording_micro_allocator.cc +++ b/tensorflow/lite/micro/recording_micro_allocator.cc
@@ -78,9 +78,14 @@ 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*