规范性整改并与黄区代码同步2

Signed-off-by: zhangdd_ewan <zhangdongdong50@huawei.com>
This commit is contained in:
zhangdd_ewan 2023-05-19 14:26:18 +08:00
parent 194a259f5f
commit ff707c4a3b
7 changed files with 35 additions and 19 deletions

View File

@ -17,6 +17,7 @@
#include <cstdint>
#include <map>
#include <png.h>
#include <set>
#include <string>
#include "i18n_types.h"
@ -81,6 +82,7 @@ private:
static void GetTimezoneIDFromZoneInfo(std::set<std::string> &availableIDs, std::string &parentPath,
std::string &parentName);
static std::vector<int> GetColorData(const int x, const int y);
static int InitPngptr(png_structp &png_ptr, png_infop &info_ptr, FILE **fp);
};
} // namespace I18n
} // namespace Global

View File

@ -34,7 +34,6 @@
#include "unicode/locid.h"
#include "unicode/unistr.h"
#include "utils.h"
#include <png.h>
#include <cstdio>
namespace OHOS {
@ -1002,25 +1001,11 @@ std::vector<int> I18nTimeZone::GetColorData(const int x, const int y)
return result;
}
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
png_bytep row_pointers;
fp = fopen(TZ_PIXEL_PATH, "rb");
if (fp == NULL) {
HiLog::Error(LABEL, "timezone data resource file not exists.");
return result;
}
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
HiLog::Error(LABEL, "create read_struct failed.");
return result;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
HiLog::Error(LABEL, "create info_struct failed.");
int code = InitPngptr(png_ptr, info_ptr, &fp);
if (code != 0) {
return result;
}
try {
@ -1029,7 +1014,7 @@ std::vector<int> I18nTimeZone::GetColorData(const int x, const int y)
png_read_info(png_ptr, info_ptr);
unsigned int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
row_pointers = (png_bytep)png_malloc(png_ptr, rowbytes);
if (row_pointers == NULL) {
if (row_pointers == nullptr) {
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
HiLog::Error(LABEL, "malloc rowbytes failed.");
@ -1051,6 +1036,30 @@ std::vector<int> I18nTimeZone::GetColorData(const int x, const int y)
fclose(fp);
return result;
}
int I18nTimeZone::InitPngptr(png_structp &png_ptr, png_infop &info_ptr, FILE **fp)
{
*fp = fopen(TZ_PIXEL_PATH, "rb");
if (*fp == NULL) {
HiLog::Error(LABEL, "timezone data resource file not exists.");
return 1;
}
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(*fp);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
HiLog::Error(LABEL, "create read_struct failed.");
return 1;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
fclose(*fp);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
HiLog::Error(LABEL, "create info_struct failed.");
return 1;
}
return 0;
}
}
}
}

View File

@ -37,6 +37,7 @@ ohos_unittest("intl_test") {
"//third_party/googletest:gtest_main",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libpng:libpng",
]
}

View File

@ -28,5 +28,6 @@ group("fuzztest") {
"relativetimeformat_fuzzer:RelativeTimeFormatFuzzTest",
"timezone_fuzzer:TimeZoneFuzzTest",
"utils_fuzzer:UtilsFuzzTest",
"//third_party/libpng:libpng",
]
}

View File

@ -43,6 +43,7 @@ ohos_fuzztest("TimeZoneFuzzTest") {
"//base/global/i18n/frameworks/intl:intl_util",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libpng:libpng",
]
subsystem_name = "global"

View File

@ -42,6 +42,7 @@ ohos_shared_library("zone_util") {
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libphonenumber/cpp:phonenumber_standard",
"//third_party/libpng:libpng",
"//third_party/libxml2:xml2",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]

View File

@ -75,6 +75,7 @@ ohos_shared_library("i18n") {
"//base/global/i18n/frameworks/intl:preferred_language",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libpng:libpng",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",