src: fix warning for potential snprintf truncation

gcc 8+ recognizes that space has not been left for the pid and that the
return value of snprintf() isn't checked. Leave a little space for the
pid to prevent `-Wformat-truncation`.

PR-URL: https://github.com/nodejs/node/pull/24810
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
Sam Roberts 2018-12-03 09:07:53 -08:00
parent bcef949c93
commit a9a5956576

View File

@ -116,7 +116,8 @@ std::string GetHumanReadableProcessName() {
}
void GetHumanReadableProcessName(char (*name)[1024]) {
char title[1024] = "Node.js";
// Leave room after title for pid, which can be up to 20 digits for 64 bit.
char title[1000] = "Node.js";
uv_get_process_title(title, sizeof(title));
snprintf(*name, sizeof(*name), "%s[%d]", title, uv_os_getpid());
}