Skip to content

Commit 4f3d607

Browse files
arsenmlamb-j
authored andcommitted
comgr: Fix warning about not using snprintf
Change-Id: I1c952c790f9eb0ca952698e9abe2f950f3608f76
1 parent 05b04ae commit 4f3d607

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

amd/comgr/src/comgr-compiler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,10 @@ amd_comgr_status_t AMDGPUCompiler::unbundle() {
12941294

12951295
// Generate random name if none provided
12961296
if (!strcmp(Input->Name, "")) {
1297-
char *buf = (char *) malloc(sizeof(char) * 30);
1298-
sprintf(buf,"comgr-bundle-%d.%s", std::rand() % 10000,
1299-
FileExtension.c_str());
1297+
const size_t buf_size = sizeof(char) * 30;
1298+
char *buf = (char *)malloc(buf_size);
1299+
snprintf(buf, buf_size, "comgr-bundle-%d.%s", std::rand() % 10000,
1300+
FileExtension.c_str());
13001301
Input->Name = buf;
13011302
}
13021303

@@ -1419,8 +1420,9 @@ amd_comgr_status_t AMDGPUCompiler::linkBitcodeToBitcode() {
14191420
// string to assign. This string is used when the DataObject is written
14201421
// to the file system via SAVE_TEMPS, or if the object is a bundle which
14211422
// also needs a file system write for unpacking
1422-
char *buf = (char *) malloc(sizeof(char) * 30);
1423-
sprintf(buf,"comgr-anon-bitcode-%d.bc", std::rand() % 10000);
1423+
const size_t buf_size = sizeof(char) * 30;
1424+
char *buf = (char *)malloc(buf_size);
1425+
snprintf(buf, buf_size, "comgr-anon-bitcode-%d.bc", std::rand() % 10000);
14241426

14251427
Input->Name = buf;
14261428
}

0 commit comments

Comments
 (0)