Skip to content

Commit a7b3dd3

Browse files
authored
Fix compiler warnings. (#9055)
1 parent 2acd78b commit a7b3dd3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/collective/aggregator.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ namespace collective {
3232
* @param function The function used to calculate the results.
3333
* @param args Arguments to the function.
3434
*/
35-
template <typename Function, typename... Args>
36-
void ApplyWithLabels(MetaInfo const& info, void* buffer, size_t size, Function&& function,
35+
template <typename Function, typename T, typename... Args>
36+
void ApplyWithLabels(MetaInfo const& info, T* buffer, size_t size, Function&& function,
3737
Args&&... args) {
3838
if (info.IsVerticalFederated()) {
3939
// We assume labels are only available on worker 0, so the calculation is done there and result
4040
// broadcast to other workers.
41-
std::vector<char> message(1024);
41+
std::string message;
4242
if (collective::GetRank() == 0) {
4343
try {
4444
std::forward<Function>(function)(std::forward<Args>(args)...);
4545
} catch (dmlc::Error& e) {
46-
strncpy(&message[0], e.what(), message.size());
47-
message.back() = '\0';
46+
message = e.what();
4847
}
4948
}
50-
collective::Broadcast(&message[0], message.size(), 0);
51-
if (strlen(&message[0]) == 0) {
49+
50+
collective::Broadcast(&message, 0);
51+
if (message.empty()) {
5252
collective::Broadcast(buffer, size, 0);
5353
} else {
5454
LOG(FATAL) << &message[0];
@@ -57,6 +57,5 @@ void ApplyWithLabels(MetaInfo const& info, void* buffer, size_t size, Function&&
5757
std::forward<Function>(function)(std::forward<Args>(args)...);
5858
}
5959
}
60-
6160
} // namespace collective
6261
} // namespace xgboost

0 commit comments

Comments
 (0)