Skip to content

Commit

Permalink
Static Code Analysis result Update (#2624)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Johnney-Jung authored Jul 16, 2024
1 parent ff5c090 commit 7a02496
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tensorflow/lite/micro/micro_allocation_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 3 additions & 1 deletion tensorflow/lite/micro/micro_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
4 changes: 3 additions & 1 deletion tensorflow/lite/micro/micro_interpreter_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
5 changes: 4 additions & 1 deletion tensorflow/lite/micro/micro_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions tensorflow/lite/micro/recording_micro_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down

0 comments on commit 7a02496

Please sign in to comment.