From de582d4796c00cc49f9142691b78ae7e5c0ec298 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Fri, 22 Dec 2023 11:08:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?strcpy=E5=87=BD=E6=95=B0=E6=9C=89=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E9=A3=8E=E9=99=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- bundle.json | 1 + cpp/BUILD.gn | 3 +++ cpp/src/phonenumbers/geocoding/geocoding_warpper.cc | 8 +++++--- cpp/src/phonenumbers/geocoding/geocoding_warpper.h | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bundle.json b/bundle.json index 3bd0fba..e0f6dab 100644 --- a/bundle.json +++ b/bundle.json @@ -21,6 +21,7 @@ "components": [], "third_party": [ "abseil-cpp", + "bounds_checking_function", "icu", "protobuf" ] diff --git a/cpp/BUILD.gn b/cpp/BUILD.gn index 4f4b577..34635df 100644 --- a/cpp/BUILD.gn +++ b/cpp/BUILD.gn @@ -22,6 +22,7 @@ group("build_module") { config("phonenumber_config") { include_dirs = [ "//third_party/abseil-cpp/abseil-cpp", + "//third_party/bounds_checking_function/include", "//third_party/icu/icu4c/source/common", "//third_party/icu/icu4c/source/i18n", "//third_party/icu/icu4c/source", @@ -79,6 +80,7 @@ ohos_shared_library("phonenumber_standard") { deps = [ "//third_party/abseil-cpp:absl_base", "//third_party/abseil-cpp:absl_strings", + "//third_party/bounds_checking_function:libsec_shared", "//third_party/icu/icu4c:shared_icui18n", "//third_party/icu/icu4c:shared_icuuc", "//third_party/protobuf:protobuf_lite", @@ -107,6 +109,7 @@ ohos_shared_library("geocoding") { "src/phonenumbers/phonenumber.pb.h", ] deps = [ + "//third_party/bounds_checking_function:libsec_shared", "//third_party/icu/icu4c:shared_icuuc", "//third_party/libphonenumber/cpp:phonenumber_standard", ] diff --git a/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc b/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc index b78ac99..b062b27 100644 --- a/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc +++ b/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc @@ -9,6 +9,7 @@ #include #include // NOLINT(build/include_order) #include +#include "securec.h" using icu::UnicodeString; using i18n::phonenumbers::PhoneNumber; @@ -16,7 +17,7 @@ using i18n::phonenumbers::PhoneNumberUtil; using i18n::phonenumbers::PhoneNumberOfflineGeocoder; using icu::Locale; -extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res) { +extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength = 128) { if(offlineGeocoder == NULL) { offlineGeocoder = new PhoneNumberOfflineGeocoder(); } @@ -29,9 +30,10 @@ extern "C" void exposeLocationName(const char* pNumber, const char* locale, char PhoneNumberUtil::ErrorType type = util->Parse(number, uLocale.getCountry(), &phoneNumber); if (type != PhoneNumberUtil::ErrorType::NO_PARSING_ERROR) { std::string empty = ""; - std::strcpy(res, empty.c_str()); + strcpy_s(res, resLength, empty.c_str()); + return; } std::string result = offlineGeocoder->GetDescriptionForNumber(phoneNumber, uLocale); - std::strcpy(res, result.c_str()); + strcpy_s(res, resLength, result.c_str()); } diff --git a/cpp/src/phonenumbers/geocoding/geocoding_warpper.h b/cpp/src/phonenumbers/geocoding/geocoding_warpper.h index ca5141f..2020a51 100644 --- a/cpp/src/phonenumbers/geocoding/geocoding_warpper.h +++ b/cpp/src/phonenumbers/geocoding/geocoding_warpper.h @@ -9,4 +9,4 @@ using i18n::phonenumbers::PhoneNumberOfflineGeocoder; PhoneNumberOfflineGeocoder* offlineGeocoder = NULL; i18n::phonenumbers::PhoneNumberUtil* util = NULL; -extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res); +extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength); -- Gitee From 1c1369b6c41aa1bab70864eee88d415c4095ba65 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Fri, 29 Dec 2023 09:46:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?strcpy=E5=87=BD=E6=95=B0=E6=9C=89=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E9=A3=8E=E9=99=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- cpp/src/phonenumbers/geocoding/geocoding_warpper.cc | 7 +++---- cpp/src/phonenumbers/geocoding/geocoding_warpper.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc b/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc index b062b27..fe46b61 100644 --- a/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc +++ b/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc @@ -17,7 +17,7 @@ using i18n::phonenumbers::PhoneNumberUtil; using i18n::phonenumbers::PhoneNumberOfflineGeocoder; using icu::Locale; -extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength = 128) { +extern "C" int exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength = 128) { if(offlineGeocoder == NULL) { offlineGeocoder = new PhoneNumberOfflineGeocoder(); } @@ -30,10 +30,9 @@ extern "C" void exposeLocationName(const char* pNumber, const char* locale, char PhoneNumberUtil::ErrorType type = util->Parse(number, uLocale.getCountry(), &phoneNumber); if (type != PhoneNumberUtil::ErrorType::NO_PARSING_ERROR) { std::string empty = ""; - strcpy_s(res, resLength, empty.c_str()); - return; + return strcpy_s(res, resLength, empty.c_str()); } std::string result = offlineGeocoder->GetDescriptionForNumber(phoneNumber, uLocale); - strcpy_s(res, resLength, result.c_str()); + return strcpy_s(res, resLength, result.c_str()); } diff --git a/cpp/src/phonenumbers/geocoding/geocoding_warpper.h b/cpp/src/phonenumbers/geocoding/geocoding_warpper.h index 2020a51..b3d00ff 100644 --- a/cpp/src/phonenumbers/geocoding/geocoding_warpper.h +++ b/cpp/src/phonenumbers/geocoding/geocoding_warpper.h @@ -9,4 +9,4 @@ using i18n::phonenumbers::PhoneNumberOfflineGeocoder; PhoneNumberOfflineGeocoder* offlineGeocoder = NULL; i18n::phonenumbers::PhoneNumberUtil* util = NULL; -extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength); +extern "C" int exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength); -- Gitee