Skip to content

Commit 80ab094

Browse files
author
David Holmes
committed
8347707: Standardise the use of os::snprintf and os::snprintf_checked
Reviewed-by: kbarrett, fbredberg
1 parent bdc3981 commit 80ab094

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+195
-183
lines changed

src/hotspot/cpu/aarch64/frame_aarch64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,10 @@ static void printbc(Method *m, intptr_t bcx) {
702702
if (m->validate_bci_from_bcp((address)bcx) < 0
703703
|| !m->contains((address)bcx)) {
704704
name = "???";
705-
snprintf(buf, sizeof buf, "(bad)");
705+
os::snprintf_checked(buf, sizeof buf, "(bad)");
706706
} else {
707707
int bci = m->bci_from((address)bcx);
708-
snprintf(buf, sizeof buf, "%d", bci);
708+
os::snprintf_checked(buf, sizeof buf, "%d", bci);
709709
name = Bytecodes::name(m->code_at(bci));
710710
}
711711
ResourceMark rm;

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ void MacroAssembler::movptr(Register r, uintptr_t imm64) {
22592259
#ifndef PRODUCT
22602260
{
22612261
char buffer[64];
2262-
snprintf(buffer, sizeof(buffer), "0x%" PRIX64, (uint64_t)imm64);
2262+
os::snprintf_checked(buffer, sizeof(buffer), "0x%" PRIX64, (uint64_t)imm64);
22632263
block_comment(buffer);
22642264
}
22652265
#endif
@@ -2317,7 +2317,7 @@ void MacroAssembler::mov_immediate64(Register dst, uint64_t imm64)
23172317
#ifndef PRODUCT
23182318
{
23192319
char buffer[64];
2320-
snprintf(buffer, sizeof(buffer), "0x%" PRIX64, imm64);
2320+
os::snprintf_checked(buffer, sizeof(buffer), "0x%" PRIX64, imm64);
23212321
block_comment(buffer);
23222322
}
23232323
#endif
@@ -2430,7 +2430,7 @@ void MacroAssembler::mov_immediate32(Register dst, uint32_t imm32)
24302430
#ifndef PRODUCT
24312431
{
24322432
char buffer[64];
2433-
snprintf(buffer, sizeof(buffer), "0x%" PRIX32, imm32);
2433+
os::snprintf_checked(buffer, sizeof(buffer), "0x%" PRIX32, imm32);
24342434
block_comment(buffer);
24352435
}
24362436
#endif
@@ -2902,11 +2902,11 @@ int MacroAssembler::push_fp(unsigned int bitset, Register stack, FpPushPopMode m
29022902
{
29032903
char buffer[48];
29042904
if (mode == PushPopSVE) {
2905-
snprintf(buffer, sizeof(buffer), "push_fp: %d SVE registers", count);
2905+
os::snprintf_checked(buffer, sizeof(buffer), "push_fp: %d SVE registers", count);
29062906
} else if (mode == PushPopNeon) {
2907-
snprintf(buffer, sizeof(buffer), "push_fp: %d Neon registers", count);
2907+
os::snprintf_checked(buffer, sizeof(buffer), "push_fp: %d Neon registers", count);
29082908
} else {
2909-
snprintf(buffer, sizeof(buffer), "push_fp: %d fp registers", count);
2909+
os::snprintf_checked(buffer, sizeof(buffer), "push_fp: %d fp registers", count);
29102910
}
29112911
block_comment(buffer);
29122912
}
@@ -3014,11 +3014,11 @@ int MacroAssembler::pop_fp(unsigned int bitset, Register stack, FpPushPopMode mo
30143014
{
30153015
char buffer[48];
30163016
if (mode == PushPopSVE) {
3017-
snprintf(buffer, sizeof(buffer), "pop_fp: %d SVE registers", count);
3017+
os::snprintf_checked(buffer, sizeof(buffer), "pop_fp: %d SVE registers", count);
30183018
} else if (mode == PushPopNeon) {
3019-
snprintf(buffer, sizeof(buffer), "pop_fp: %d Neon registers", count);
3019+
os::snprintf_checked(buffer, sizeof(buffer), "pop_fp: %d Neon registers", count);
30203020
} else {
3021-
snprintf(buffer, sizeof(buffer), "pop_fp: %d fp registers", count);
3021+
os::snprintf_checked(buffer, sizeof(buffer), "pop_fp: %d fp registers", count);
30223022
}
30233023
block_comment(buffer);
30243024
}
@@ -5920,7 +5920,7 @@ address MacroAssembler::arrays_equals(Register a1, Register a2, Register tmp3,
59205920
{
59215921
const char kind = (elem_size == 2) ? 'U' : 'L';
59225922
char comment[64];
5923-
snprintf(comment, sizeof comment, "array_equals%c{", kind);
5923+
os::snprintf_checked(comment, sizeof comment, "array_equals%c{", kind);
59245924
BLOCK_COMMENT(comment);
59255925
}
59265926
#endif
@@ -6118,7 +6118,7 @@ void MacroAssembler::string_equals(Register a1, Register a2,
61186118
#ifndef PRODUCT
61196119
{
61206120
char comment[64];
6121-
snprintf(comment, sizeof comment, "{string_equalsL");
6121+
os::snprintf_checked(comment, sizeof comment, "{string_equalsL");
61226122
BLOCK_COMMENT(comment);
61236123
}
61246124
#endif
@@ -6266,7 +6266,7 @@ address MacroAssembler::zero_words(Register base, uint64_t cnt)
62666266
#ifndef PRODUCT
62676267
{
62686268
char buf[64];
6269-
snprintf(buf, sizeof buf, "zero_words (count = %" PRIu64 ") {", cnt);
6269+
os::snprintf_checked(buf, sizeof buf, "zero_words (count = %" PRIu64 ") {", cnt);
62706270
BLOCK_COMMENT(buf);
62716271
}
62726272
#endif

src/hotspot/cpu/aarch64/vm_version_aarch64.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,12 +721,12 @@ void VM_Version::initialize_cpu_information(void) {
721721
_no_of_cores = os::processor_count();
722722
_no_of_threads = _no_of_cores;
723723
_no_of_sockets = _no_of_cores;
724-
snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "AArch64");
724+
os::snprintf_checked(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "AArch64");
725725

726-
int desc_len = snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "AArch64 ");
726+
int desc_len = os::snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "AArch64 ");
727727
get_compatible_board(_cpu_desc + desc_len, CPU_DETAILED_DESC_BUF_SIZE - desc_len);
728728
desc_len = (int)strlen(_cpu_desc);
729-
snprintf(_cpu_desc + desc_len, CPU_DETAILED_DESC_BUF_SIZE - desc_len, " %s", _cpu_info_string);
729+
os::snprintf_checked(_cpu_desc + desc_len, CPU_DETAILED_DESC_BUF_SIZE - desc_len, " %s", _cpu_info_string);
730730

731731
_initialized = true;
732732
}

src/hotspot/cpu/arm/macroAssembler_arm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file,
839839
char buffer[64];
840840
#ifdef COMPILER1
841841
if (CommentedAssembly) {
842-
snprintf(buffer, sizeof(buffer), "verify_oop at %d", offset());
842+
os::snprintf_checked(buffer, sizeof(buffer), "verify_oop at %d", offset());
843843
block_comment(buffer);
844844
}
845845
#endif

src/hotspot/cpu/arm/vm_version_arm_32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void VM_Version::initialize_cpu_information(void) {
362362
_no_of_cores = os::processor_count();
363363
_no_of_threads = _no_of_cores;
364364
_no_of_sockets = _no_of_cores;
365-
snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "ARM%d", _arm_arch);
366-
snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "%s", _cpu_info_string);
365+
os::snprintf_checked(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "ARM%d", _arm_arch);
366+
os::snprintf_checked(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "%s", _cpu_info_string);
367367
_initialized = true;
368368
}

src/hotspot/cpu/ppc/vm_version_ppc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ void VM_Version::initialize_cpu_information(void) {
625625
_no_of_cores = os::processor_count();
626626
_no_of_threads = _no_of_cores;
627627
_no_of_sockets = _no_of_cores;
628-
snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE, "PowerPC POWER%lu", PowerArchitecturePPC64);
629-
snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "PPC %s", cpu_info_string());
628+
os::snprintf_checked(_cpu_name, CPU_TYPE_DESC_BUF_SIZE, "PowerPC POWER%lu", PowerArchitecturePPC64);
629+
os::snprintf_checked(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "PPC %s", cpu_info_string());
630630
_initialized = true;
631631
}

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,7 @@ void MacroAssembler::movptr(Register Rd, address addr, int32_t &offset, Register
26792679
#ifndef PRODUCT
26802680
{
26812681
char buffer[64];
2682-
snprintf(buffer, sizeof(buffer), "0x%" PRIx64, uimm64);
2682+
os::snprintf_checked(buffer, sizeof(buffer), "0x%" PRIx64, uimm64);
26832683
block_comment(buffer);
26842684
}
26852685
#endif

src/hotspot/cpu/riscv/vm_version_riscv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ void VM_Version::initialize_cpu_information(void) {
493493
_no_of_cores = os::processor_count();
494494
_no_of_threads = _no_of_cores;
495495
_no_of_sockets = _no_of_cores;
496-
snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "RISCV64");
497-
snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "RISCV64 %s", cpu_info_string());
496+
os::snprintf_checked(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "RISCV64");
497+
os::snprintf_checked(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "RISCV64 %s", cpu_info_string());
498498
_initialized = true;
499499
}
500500

src/hotspot/cpu/s390/vm_version_s390.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ void VM_Version::initialize_cpu_information(void) {
15491549
_no_of_cores = os::processor_count();
15501550
_no_of_threads = _no_of_cores;
15511551
_no_of_sockets = _no_of_cores;
1552-
snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE, "s390 %s", VM_Version::get_model_string());
1553-
snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "s390 %s", cpu_info_string());
1552+
os::snprintf_checked(_cpu_name, CPU_TYPE_DESC_BUF_SIZE, "s390 %s", VM_Version::get_model_string());
1553+
os::snprintf_checked(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "s390 %s", cpu_info_string());
15541554
_initialized = true;
15551555
}

src/hotspot/cpu/x86/stubGenerator_x86_64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,10 +4331,10 @@ void StubGenerator::generate_compiler_stubs() {
43314331
if (libsimdsort != nullptr) {
43324332
log_info(library)("Loaded library %s, handle " INTPTR_FORMAT, JNI_LIB_PREFIX "simdsort" JNI_LIB_SUFFIX, p2i(libsimdsort));
43334333

4334-
snprintf(ebuf_, sizeof(ebuf_), VM_Version::supports_avx512_simd_sort() ? "avx512_sort" : "avx2_sort");
4334+
os::snprintf_checked(ebuf_, sizeof(ebuf_), VM_Version::supports_avx512_simd_sort() ? "avx512_sort" : "avx2_sort");
43354335
StubRoutines::_array_sort = (address)os::dll_lookup(libsimdsort, ebuf_);
43364336

4337-
snprintf(ebuf_, sizeof(ebuf_), VM_Version::supports_avx512_simd_sort() ? "avx512_partition" : "avx2_partition");
4337+
os::snprintf_checked(ebuf_, sizeof(ebuf_), VM_Version::supports_avx512_simd_sort() ? "avx512_partition" : "avx2_partition");
43384338
StubRoutines::_array_partition = (address)os::dll_lookup(libsimdsort, ebuf_);
43394339
}
43404340
}

0 commit comments

Comments
 (0)