提交 a9a90d60 编写于 作者: D dujingcheng

strcpy to strcpy_s

Signed-off-by: Ndujingcheng <dujingcheng@huawei.com>
Change-Id: Ia942394c7bf61561853100ff12a5d1bb17516b60
上级 b8189795
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <securec.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
...@@ -35,6 +36,7 @@ static int ONE = 1; ...@@ -35,6 +36,7 @@ static int ONE = 1;
static int FOUR = 4; static int FOUR = 4;
static int SIX = 6; static int SIX = 6;
static int EIGHT = 8; static int EIGHT = 8;
static int GARBAGE_LEN = strlen(GARBAGE);
static unsigned BUFFER_SIZE = 8192; static unsigned BUFFER_SIZE = 8192;
} }
...@@ -125,7 +127,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestCompress, Function | MediumTest | Level2) ...@@ -125,7 +127,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestCompress, Function | MediumTest | Level2)
fprintf(stderr, "compress error: %d\n", err); fprintf(stderr, "compress error: %d\n", err);
ASSERT_EQ(err, Z_OK); ASSERT_EQ(err, Z_OK);
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
err = uncompress(uncompr, &uncomprLen, compr, comprLen); err = uncompress(uncompr, &uncomprLen, compr, comprLen);
fprintf(stderr, "uncompress error: %d\n", err); fprintf(stderr, "uncompress error: %d\n", err);
ASSERT_EQ(err, Z_OK); ASSERT_EQ(err, Z_OK);
...@@ -171,7 +173,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzio, Function | MediumTest | Level2) ...@@ -171,7 +173,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzio, Function | MediumTest | Level2)
uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE)); uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL); ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL);
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
ASSERT_TRUE(gzread(file, uncompr, static_cast<unsigned>(uncomprLen)) == len); ASSERT_TRUE(gzread(file, uncompr, static_cast<unsigned>(uncomprLen)) == len);
ASSERT_FALSE(strcmp(reinterpret_cast<char *>(uncompr), HELLO)); ASSERT_FALSE(strcmp(reinterpret_cast<char *>(uncompr), HELLO));
...@@ -253,7 +255,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflate, Function | MediumTest | Level2) ...@@ -253,7 +255,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflate, Function | MediumTest | Level2)
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -356,7 +358,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestLargeInflate, Function | MediumTest | Level2) ...@@ -356,7 +358,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestLargeInflate, Function | MediumTest | Level2)
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -438,7 +440,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestSync, Function | MediumTest | Level2) ...@@ -438,7 +440,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestSync, Function | MediumTest | Level2)
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -515,7 +517,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestDictInflate, Function | MediumTest | Level2) ...@@ -515,7 +517,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestDictInflate, Function | MediumTest | Level2)
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -577,7 +579,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestCompress2, Function | MediumTest | Level2) ...@@ -577,7 +579,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestCompress2, Function | MediumTest | Level2)
fprintf(stderr, "compress2 Z_BEST_COMPRESSION result: %d\n", err); fprintf(stderr, "compress2 Z_BEST_COMPRESSION result: %d\n", err);
ASSERT_EQ(err, Z_OK); ASSERT_EQ(err, Z_OK);
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
err = uncompress2(uncompr, &uncomprLen, compr, &comprLen); err = uncompress2(uncompr, &uncomprLen, compr, &comprLen);
fprintf(stderr, "uncompress2 Z_BEST_COMPRESSION result: %d\n", err); fprintf(stderr, "uncompress2 Z_BEST_COMPRESSION result: %d\n", err);
ASSERT_EQ(err, Z_OK); ASSERT_EQ(err, Z_OK);
...@@ -806,7 +808,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzBuffer, Function | MediumTest | Level2) ...@@ -806,7 +808,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzBuffer, Function | MediumTest | Level2)
uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE)); uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL); ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL);
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
ASSERT_TRUE(gzread(file, uncompr, static_cast<unsigned>(uncomprLen)) == len); ASSERT_TRUE(gzread(file, uncompr, static_cast<unsigned>(uncomprLen)) == len);
ASSERT_FALSE(strcmp(reinterpret_cast<char *>(uncompr), HELLO)); ASSERT_FALSE(strcmp(reinterpret_cast<char *>(uncompr), HELLO));
...@@ -950,7 +952,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzGets, Function | MediumTest | Level2) ...@@ -950,7 +952,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzGets, Function | MediumTest | Level2)
Byte *uncompr; Byte *uncompr;
uLong uncomprLen = 10000 * sizeof(int); uLong uncomprLen = 10000 * sizeof(int);
uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE)); uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
fprintf(stderr, "gzgets\n"); fprintf(stderr, "gzgets\n");
gzgets(file, reinterpret_cast<char *>(uncompr), static_cast<int>(uncomprLen)); gzgets(file, reinterpret_cast<char *>(uncompr), static_cast<int>(uncomprLen));
ASSERT_TRUE(strcmp(reinterpret_cast<char *>(uncompr), HELLO + SIX)); ASSERT_TRUE(strcmp(reinterpret_cast<char *>(uncompr), HELLO + SIX));
...@@ -1118,7 +1120,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzRead, Function | MediumTest | Level2) ...@@ -1118,7 +1120,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzRead, Function | MediumTest | Level2)
uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE)); uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
ASSERT_TRUE(uncompr != Z_NULL); ASSERT_TRUE(uncompr != Z_NULL);
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
ASSERT_TRUE(gzread(file, uncompr, static_cast<unsigned>(uncomprLen)) == len); ASSERT_TRUE(gzread(file, uncompr, static_cast<unsigned>(uncomprLen)) == len);
gzclose(file); gzclose(file);
#endif #endif
...@@ -1333,7 +1335,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateCodesUsed, Function | MediumTest | Lev ...@@ -1333,7 +1335,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateCodesUsed, Function | MediumTest | Lev
ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL); ASSERT_TRUE(compr != Z_NULL && uncompr != Z_NULL);
unsigned long err; unsigned long err;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -1378,7 +1380,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateGetDictionary, Function | MediumTest | ...@@ -1378,7 +1380,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateGetDictionary, Function | MediumTest |
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -1548,7 +1550,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateReset, Function | MediumTest | Level2) ...@@ -1548,7 +1550,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateReset, Function | MediumTest | Level2)
int err = Z_OK; int err = Z_OK;
int windowBits = 8; int windowBits = 8;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -1586,7 +1588,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateSetDictionary, Function | MediumTest | ...@@ -1586,7 +1588,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateSetDictionary, Function | MediumTest |
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -1620,7 +1622,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateSyncPoint, Function | MediumTest | Lev ...@@ -1620,7 +1622,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateSyncPoint, Function | MediumTest | Lev
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -1652,7 +1654,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateUndermine, Function | MediumTest | Lev ...@@ -1652,7 +1654,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateUndermine, Function | MediumTest | Lev
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
...@@ -1684,7 +1686,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateValidate, Function | MediumTest | Leve ...@@ -1684,7 +1686,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestInflateValidate, Function | MediumTest | Leve
int err = Z_OK; int err = Z_OK;
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
strcpy(reinterpret_cast<char *>(uncompr), GARBAGE); strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr; d_stream.zalloc = nullptr;
d_stream.zfree = nullptr; d_stream.zfree = nullptr;
d_stream.opaque = nullptr; d_stream.opaque = nullptr;
......
...@@ -20,4 +20,5 @@ ohos_moduletest_suite("ActsZlibTest") { ...@@ -20,4 +20,5 @@ ohos_moduletest_suite("ActsZlibTest") {
configs = [ "//third_party/zlib:zlib_config" ] configs = [ "//third_party/zlib:zlib_config" ]
public_configs = [ "//third_party/zlib:zlib_public_config" ] public_configs = [ "//third_party/zlib:zlib_public_config" ]
deps = [ "//third_party/zlib:libz" ] deps = [ "//third_party/zlib:libz" ]
external_deps = [ "utils_base:utils" ]
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册