Commit fa0ec09f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Fix two warnings issued by g++

A local build with g++ 8.3.0 failed with two warnings. This CL fixes
them.
The errors were:

1) error: 'char* strncat(char*, const char*, size_t)' output truncated
   before terminating nul copying as many bytes from a string as its
   length [-Werror=stringop-truncation]
2) error: 'char* strncpy(char*, const char*, size_t)' specified bound
   depends on the length of the source argument
   [-Werror=stringop-overflow=]

R=petermarshall@chromium.org

Bug: v8:9396
Change-Id: I175a72435becd694e4151a64e538084ec17d8500
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1803636Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63788}
parent 61085f2c
......@@ -21,11 +21,10 @@ char* RelativePath(char** buffer, const char* exec_path, const char* name) {
}
if (path_separator >= 0) {
int name_length = static_cast<int>(strlen(name));
*buffer =
reinterpret_cast<char*>(calloc(path_separator + name_length + 2, 1));
*buffer[0] = '\0';
strncat(*buffer, exec_path, path_separator + 1);
strncat(*buffer, name, name_length);
*buffer = reinterpret_cast<char*>(malloc(path_separator + name_length + 2));
memcpy(*buffer, exec_path, path_separator + 1);
memcpy(*buffer + path_separator + 1, name, name_length);
(*buffer)[path_separator + name_length + 1] = '\0';
} else {
*buffer = strdup(name);
}
......
......@@ -23,12 +23,11 @@ V8_INLINE static size_t GetAllocLength(const char* str) {
// location, and then advances |*buffer| by the amount written.
V8_INLINE static void CopyTraceObjectParameter(char** buffer,
const char** member) {
if (*member) {
size_t length = strlen(*member) + 1;
strncpy(*buffer, *member, length);
*member = *buffer;
*buffer += length;
}
if (*member == nullptr) return;
size_t length = strlen(*member) + 1;
memcpy(*buffer, *member, length);
*member = *buffer;
*buffer += length;
}
void TraceObject::Initialize(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment