diff options
author | Yunlian Jiang <yunlian@google.com> | 2017-09-13 12:01:15 -0700 |
---|---|---|
committer | Yunlian Jiang <yunlian@google.com> | 2017-09-26 16:02:11 -0700 |
commit | d32ae10f4cdcff2351c9f34ce477089111093d32 (patch) | |
tree | 5e21a2fdab6f1d10e8e7dd8c5cc60248b8bce471 /tools/aapt | |
parent | 2cdd1ce6001e642f65456f6504cbb7d11cd1469d (diff) |
Replace strcpy with memcpy.
This fixes the warning
Call to function 'strcpy' is insecure as it does not provide bounding of
the memory buffer. As a side effect, it sliences the warning
frameworks/base/tools/aapt/Images.cpp:1270:50: warning: Potential leak
of memory pointed to by field 'data' [clang-analyzer-unix.Malloc]
frameworks/base/tools/aapt2/compile/Png.cpp:562:42: warning: Potential
leak of memory pointed to by field 'data' [clang-analyzer-unix.Malloc].
Bug: None
Test: The warning is gone.
Change-Id: I25f68ff85bea7069c21549c7deb7920d1877069e
Diffstat (limited to 'tools/aapt')
-rw-r--r-- | tools/aapt/Images.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp index 5f586a15eeb8..627a231de5c8 100644 --- a/tools/aapt/Images.cpp +++ b/tools/aapt/Images.cpp @@ -1246,7 +1246,7 @@ static void write_png(const char* imageName, if (kIsDebug) { printf("Adding 9-patch info...\n"); } - strcpy((char*)unknowns[p_index].name, "npTc"); + memcpy((char*)unknowns[p_index].name, "npTc", 5); unknowns[p_index].data = (png_byte*)imageInfo.serialize9patch(); unknowns[p_index].size = imageInfo.info9Patch.serializedSize(); // TODO: remove the check below when everything works @@ -1254,7 +1254,7 @@ static void write_png(const char* imageName, // automatically generated 9 patch outline data int chunk_size = sizeof(png_uint_32) * 6; - strcpy((char*)unknowns[o_index].name, "npOl"); + memcpy((char*)unknowns[o_index].name, "npOl", 5); unknowns[o_index].data = (png_byte*) calloc(chunk_size, 1); png_byte outputData[chunk_size]; memcpy(&outputData, &imageInfo.outlineInsetsLeft, 4 * sizeof(png_uint_32)); @@ -1266,7 +1266,7 @@ static void write_png(const char* imageName, // optional optical inset / layout bounds data if (imageInfo.haveLayoutBounds) { int chunk_size = sizeof(png_uint_32) * 4; - strcpy((char*)unknowns[b_index].name, "npLb"); + memcpy((char*)unknowns[b_index].name, "npLb", 5); unknowns[b_index].data = (png_byte*) calloc(chunk_size, 1); memcpy(unknowns[b_index].data, &imageInfo.layoutBoundsLeft, chunk_size); unknowns[b_index].size = chunk_size; |