From b5683965ec1f609826e3a0f73b4e55b3894f0da5 Mon Sep 17 00:00:00 2001 From: jiangshuqiang Date: Tue, 27 Apr 2021 11:14:49 +0800 Subject: [PATCH] fix open source static check --- mindspore/ccsrc/debug/debugger/debugger.cc | 21 ++++++++++++--------- mindspore/ccsrc/debug/debugger/debugger.h | 6 +++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/mindspore/ccsrc/debug/debugger/debugger.cc b/mindspore/ccsrc/debug/debugger/debugger.cc index 76e798aac8..4185d77d27 100644 --- a/mindspore/ccsrc/debug/debugger/debugger.cc +++ b/mindspore/ccsrc/debug/debugger/debugger.cc @@ -237,7 +237,7 @@ bool Debugger::CheckDebuggerEnabled() { return false; } -void Debugger::CheckDebuggerEnabledParam() { +void Debugger::CheckDebuggerEnabledParam() const { // check the value of env variable ENABLE_MS_DEBUGGER const char *env_enable_char = std::getenv("ENABLE_MS_DEBUGGER"); if (env_enable_char != nullptr) { @@ -1098,16 +1098,19 @@ std::vector Debugger::CheckOpOverflow() { void Debugger::SetTrainingDone(bool training_done) { training_done_ = training_done; } -bool Debugger::CheckPort(const char *port) { - char *p = const_cast(port); +bool Debugger::CheckPort(const char *port) const { int num = 0; - if (*p == '0' && *(p + 1) != '\0') return false; - while (*p != '\0') { - if (*p < '0' || *p > '9') return false; - num = num * 10 + (*p) - '0'; - if (num < 1 || num > 65535) return false; - p++; + const int min_port_num = 1; + const int max_port_num = 65535; + if (*port == '0' && *(port + 1) != '\0') return false; + int i = 0; + while (*(port + i) != '\0') { + if (*(port + i) < '0' || *(port + i) > '9') return false; + num = num * 10 + (*(port + i)) - '0'; + if (num > max_port_num) return false; + i++; } + if (num < min_port_num) return false; return true; } diff --git a/mindspore/ccsrc/debug/debugger/debugger.h b/mindspore/ccsrc/debug/debugger/debugger.h index 3676ff4d78..166650b5b8 100644 --- a/mindspore/ccsrc/debug/debugger/debugger.h +++ b/mindspore/ccsrc/debug/debugger/debugger.h @@ -143,7 +143,7 @@ class Debugger : public std::enable_shared_from_this { void SetGraphPtr(const KernelGraphPtr &graph_ptr) { graph_ptr_ = graph_ptr; } - std::list GetGraphPtrList() { return graph_ptr_list_; } + std::list GetGraphPtrList() const { return graph_ptr_list_; } bool TensorExistsInCurrent(std::string tensor_name); @@ -164,7 +164,7 @@ class Debugger : public std::enable_shared_from_this { // check if debugger enabled bool CheckDebuggerEnabled(); - void CheckDebuggerEnabledParam(); + void CheckDebuggerEnabledParam() const; bool CheckDebuggerPartialMemoryEnabled(); @@ -219,7 +219,7 @@ class Debugger : public std::enable_shared_from_this { std::vector CheckOpOverflow(); // Check if the port is valid - bool CheckPort(const char *port); + bool CheckPort(const char *port) const; // Check if the IP is valid bool CheckIp(const char *host);