From ec4052e2e28f345e5d10e6eda13f0698d2d4d37b Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Fri, 27 Oct 2023 15:49:47 +0200 Subject: [PATCH 1/2] #2125: Fix sprintf warnings --- src/vt/group/collective/group_info_collective.cc | 5 +++-- src/vt/runtime/runtime.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/vt/group/collective/group_info_collective.cc b/src/vt/group/collective/group_info_collective.cc index 7c7075eb67..a129406f91 100644 --- a/src/vt/group/collective/group_info_collective.cc +++ b/src/vt/group/collective/group_info_collective.cc @@ -696,11 +696,12 @@ void InfoColl::finalize() { if (in_phase_two_ && send_down_finished_ == send_down_) { if (!vt_check_enabled(production_build)) { - char buf[256]; + constexpr int max_buffer_length = 256; + char buf[max_buffer_length]; buf[0] = '\0'; int cur = 0; for (auto&& elm : collective_->span_children_) { - cur += sprintf(buf + cur, "%d,", elm); + cur += snprintf(buf + cur, max_buffer_length, "%d,", elm); } auto const& num_children = collective_->span_children_.size(); diff --git a/src/vt/runtime/runtime.cc b/src/vt/runtime/runtime.cc index 7d73260004..51ace6b1c9 100644 --- a/src/vt/runtime/runtime.cc +++ b/src/vt/runtime/runtime.cc @@ -249,9 +249,10 @@ bool Runtime::hasSchedRun() const { void Runtime::pauseForDebugger() { if (theConfig()->vt_pause) { - char node_str[256]; + constexpr int max_buffer_length = 256; + char node_str[max_buffer_length]; auto node = vt::theContext() ? vt::theContext()->getNode() : -1; - sprintf(node_str, "prog-%d.pid", node); + snprintf(node_str, max_buffer_length, "prog-%d.pid", node); auto const pid = getpid(); FILE* f = fopen(node_str, "w+"); fprintf(f, "%d", pid); From 51da09ceb35a407694c6efa371ccba503ffcca4a Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Mon, 30 Oct 2023 10:40:29 +0100 Subject: [PATCH 2/2] #2125: Fix incorrect max buffer length --- src/vt/group/collective/group_info_collective.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vt/group/collective/group_info_collective.cc b/src/vt/group/collective/group_info_collective.cc index a129406f91..2ded4cc4ef 100644 --- a/src/vt/group/collective/group_info_collective.cc +++ b/src/vt/group/collective/group_info_collective.cc @@ -701,7 +701,7 @@ void InfoColl::finalize() { buf[0] = '\0'; int cur = 0; for (auto&& elm : collective_->span_children_) { - cur += snprintf(buf + cur, max_buffer_length, "%d,", elm); + cur += snprintf(buf + cur, max_buffer_length - cur, "%d,", elm); } auto const& num_children = collective_->span_children_.size();