Skip to content

Commit

Permalink
src: fix warning for potential snprintf truncation
Browse files Browse the repository at this point in the history
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: #24810
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
sam-github committed Dec 7, 2018
1 parent bcef949 commit a9a5956
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit a9a5956

Please sign in to comment.