未验证 提交 6fcfa06b 编写于 作者: O openharmony_ci 提交者: Gitee

!3296 libz strcpy 改为strcpy_s

Merge pull request !3296 from dujingcheng/libz
......@@ -18,6 +18,7 @@
#include <cstdlib>
#include <fstream>
#include <gtest/gtest.h>
#include <securec.h>
#include <sstream>
#include <string>
......@@ -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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
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_FALSE(strcmp(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
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_FALSE(strcmp(reinterpret_cast<char *>(uncompr), HELLO));
......@@ -950,7 +952,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzGets, Function | MediumTest | Level2)
Byte *uncompr;
uLong uncomprLen = 10000 * sizeof(int);
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");
gzgets(file, reinterpret_cast<char *>(uncompr), static_cast<int>(uncomprLen));
ASSERT_TRUE(strcmp(reinterpret_cast<char *>(uncompr), HELLO + SIX));
......@@ -1118,7 +1120,7 @@ HWTEST_F(ActsZlibTest, ActsZlibTestGzRead, Function | MediumTest | Level2)
uncompr = static_cast<Byte*>(calloc(static_cast<uInt>(uncomprLen), CALLOC_SIZE));
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);
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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(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<char *>(uncompr), GARBAGE);
strcpy_s(reinterpret_cast<char *>(uncompr), GARBAGE_LEN, GARBAGE);
d_stream.zalloc = nullptr;
d_stream.zfree = nullptr;
d_stream.opaque = nullptr;
......
......@@ -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" ]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册