From 63eb24948a67e4338274c5a061a59046b0b8005c Mon Sep 17 00:00:00 2001 From: dujingcheng Date: Wed, 25 May 2022 20:59:29 +0800 Subject: [PATCH] strcpy to strcpy_s Signed-off-by: dujingcheng Change-Id: I8015358721a180317c540b09df89afd0f4168536 --- appexecfwk/zlib/actszlibtest/ActsZlibTest.cpp | 36 ++++++++++--------- appexecfwk/zlib/actszlibtest/BUILD.gn | 1 + 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/appexecfwk/zlib/actszlibtest/ActsZlibTest.cpp b/appexecfwk/zlib/actszlibtest/ActsZlibTest.cpp index c8b9bbc89..3a24ba640 100644 --- a/appexecfwk/zlib/actszlibtest/ActsZlibTest.cpp +++ b/appexecfwk/zlib/actszlibtest/ActsZlibTest.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,7 @@ static int ONE = 1; static int FOUR = 4; static int SIX = 6; static int EIGHT = 8; +static int GARBAGE_LEN = strlen(GARBAGE); static unsigned BUFFER_SIZE = 8192; } @@ -125,7 +127,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestCompress, Function | MediumTest | Level2) fprintf(stderr, "compress error: %d\n", err); ASSERT_EQ(err, Z_OK); - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); err = uncompress(uncompr, &uncomprLen, compr, comprLen); fprintf(stderr, "uncompress error: %d\n", err); ASSERT_EQ(err, Z_OK); @@ -171,7 +173,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzio, Function | MediumTest | Level2) uncompr = static_cast(calloc(static_cast(uncomprLen), CALLOC_SIZE)); ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL); - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); ASSERT_TRUE(gzread(file, uncompr, static_cast(uncomprLen)) == len); ASSERT_FALSE(strcmp(reinterpret_cast(uncompr), HELLO)); @@ -253,7 +255,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflate, Function | MediumTest | Level2) int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -356,7 +358,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestLargeInflate, Function | MediumTest | Level2) int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -438,7 +440,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestSync, Function | MediumTest | Level2) int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -515,7 +517,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestDictInflate, Function | MediumTest | Level2) int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -577,7 +579,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestCompress2, Function | MediumTest | Level2) fprintf(stderr, "compress2 Z_BEST_COMPRESSION result: %d\n", err); ASSERT_EQ(err, Z_OK); - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); err = uncompress2(uncompr, &uncomprLen, compr, &comprLen); fprintf(stderr, "uncompress2 Z_BEST_COMPRESSION result: %d\n", err); ASSERT_EQ(err, Z_OK); @@ -806,7 +808,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzBuffer, Function | MediumTest | Level2) uncompr = static_cast(calloc(static_cast(uncomprLen), CALLOC_SIZE)); ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL); - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); ASSERT_TRUE(gzread(file, uncompr, static_cast(uncomprLen)) == len); ASSERT_FALSE(strcmp(reinterpret_cast(uncompr), HELLO)); @@ -950,7 +952,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzGets, Function | MediumTest | Level2) Byte *uncompr; uLong uncomprLen = 10000 * sizeof(int); uncompr = static_cast(calloc(static_cast(uncomprLen), CALLOC_SIZE)); - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); fprintf(stderr, "gzgets\n"); gzgets(file, reinterpret_cast(uncompr), static_cast(uncomprLen)); ASSERT_TRUE(strcmp(reinterpret_cast(uncompr), HELLO + SIX)); @@ -1118,7 +1120,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzRead, Function | MediumTest | Level2) uncompr = static_cast(calloc(static_cast(uncomprLen), CALLOC_SIZE)); ASSERT_TRUE(uncompr != Z_NULL); - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); ASSERT_TRUE(gzread(file, uncompr, static_cast(uncomprLen)) == len); gzclose(file); #endif @@ -1333,7 +1335,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateCodesUsed, Function | MediumTest | Lev ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL); unsigned long err; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -1378,7 +1380,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateGetDictionary, Function | MediumTest | int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -1548,7 +1550,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateReset, Function | MediumTest | Level2) int err = Z_OK; int windowBits = 8; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -1586,7 +1588,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateSetDictionary, Function | MediumTest | int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -1620,7 +1622,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateSyncPoint, Function | MediumTest | Lev int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -1652,7 +1654,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateUndermine, Function | MediumTest | Lev int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; @@ -1684,7 +1686,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateValidate, Function | MediumTest | Leve int err = Z_OK; z_stream d_stream; /* decompression stream */ - strcpy(reinterpret_cast(uncompr), GARBAGE); + strcpy_s(reinterpret_cast(uncompr), GARBAGE_LEN, GARBAGE); d_stream.zalloc = nullptr; d_stream.zfree = nullptr; d_stream.opaque = nullptr; diff --git a/appexecfwk/zlib/actszlibtest/BUILD.gn b/appexecfwk/zlib/actszlibtest/BUILD.gn index 330536956..62b9233c4 100644 --- a/appexecfwk/zlib/actszlibtest/BUILD.gn +++ b/appexecfwk/zlib/actszlibtest/BUILD.gn @@ -20,4 +20,5 @@ ohos_moduletest_suite("ActsZlibTest") { configs = [ "//third_party/zlib:zlib_config" ] public_configs = [ "//third_party/zlib:zlib_public_config" ] deps = [ "//third_party/zlib:libz" ] + external_deps = [ "utils_base:utils" ] } -- GitLab