Fix a GCC warning in Thread::set_name().

GCC emits a stringop-truncation warning because set_name() uses the
entire buffer for strncpy(). This looks potentially unsafe, though
set_name() does the right thing and add a NUL terminator immediately
after strncpy() finishes.

To make GCC happy, reduce the number of characters copied by 1.

Change-Id: I151ba3ac67e82f5ffc092a49a94e4e1769479c71
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2067514
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66393}
This commit is contained in:
Lei Zhang 2020-02-21 02:17:55 -08:00 committed by Commit Bot
parent 3d075d2975
commit 6b08f2e6bd

View File

@ -802,7 +802,7 @@ static void* ThreadEntry(void* arg) {
void Thread::set_name(const char* name) {
strncpy(name_, name, sizeof(name_));
strncpy(name_, name, sizeof(name_) - 1);
name_[sizeof(name_) - 1] = '\0';
}