Bug / compile error - fix.

path is treated as a null-terminated string, which is only guaranteed
when the buffer that strncpy copies to is at least one larger than
the maximum number of characters copied (the third argument).

Without this patch, g++ 13.2.1 gives a warning turned into an error.
master
Aleric Inglewood 2023-08-21 19:39:43 +02:00
parent 1847e2d9b9
commit d89f3d25c3
1 changed files with 3 additions and 3 deletions

View File

@ -828,11 +828,11 @@ bool unix_post_minidump_callback(const char *dump_dir,
auto dirPathLength = strlen(dump_dir);
auto idLength = strlen(minidump_id);
// The path must not be truncated.
llassert((dirPathLength + idLength + 5) <= LLApp::MAX_MINDUMP_PATH_LENGTH);
// The path must not be truncated, and we need to have room left for a terminating zero.
llassert((dirPathLength + idLength + 5) < LLApp::MAX_MINDUMP_PATH_LENGTH);
char * path = LLApp::instance()->getMiniDumpFilename();
auto remaining = LLApp::MAX_MINDUMP_PATH_LENGTH;
auto remaining = LLApp::MAX_MINDUMP_PATH_LENGTH - 1;
strncpy(path, dump_dir, remaining);
remaining -= dirPathLength;
path += dirPathLength;