Skip to content

Commit f9e907a

Browse files
committed
resolve some warnings, prefer snprinf
1 parent 0177aa2 commit f9e907a

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

test/inc/zoo/debug/rh/RobinHood.debug.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef ZOO_TEST_ROBINHOOD_DEBUGGING
22
#define ZOO_TEST_ROBINHOOD_DEBUGGING
33

4-
#include "zoo/map/RobinHood.h"
5-
64
#include <sstream>
75
#include <stdio.h>
86

@@ -24,8 +22,9 @@ auto display(
2422
constexpr auto HexPerHash = (MD::NBitsMost + 3) / 4;
2523

2624
char format[60];
27-
snprintf(format, 59, "%%0%dllx %%0%dllx %%0%dllx", HexPerSlot, HexPerSlot, HexPerPSL);
28-
25+
const auto hexPerSlot = static_cast<int>(HexPerSlot);
26+
snprintf(format, 59, "%%0%dllx %%0%dllx %%0%dllx", hexPerSlot, hexPerSlot, HexPerPSL);
27+
2928
auto swarNdx = begin / MD::NSlots;
3029
auto swarEnd = end/MD::NSlots;
3130

@@ -34,8 +33,9 @@ auto display(
3433
auto printLine =
3534
[&]() {
3635
char buffer[100];
37-
sprintf(
36+
snprintf(
3837
buffer,
38+
sizeof(buffer),
3939
format,
4040
initial.at(0), initial.hashes().at(0), initial.PSLs().at(0)
4141
);

test/inc/zoo/variant.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <tuple>
44
// provides std::tuple_element to be able to index a pack of types,
55
// indirectly includes type traits and utility
6-
#include <new>
76
#include <zoo/meta/in_place_operations.h>
87
#include <zoo/meta/traits.h>
98

test/map/RobinHood.test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <algorithm>
1010
#include <regex>
1111
#include <map>
12-
#include <sstream>
1312
#include <fstream>
1413
#include <unordered_map>
1514

@@ -54,22 +53,23 @@ struct V {
5453

5554
std::ostream &operator<<(std::ostream &out, V v) {
5655
char buffer[30];
56+
const auto bufferSize = sizeof(buffer);
5757
char *ptr = buffer;
5858
auto val = v.v;
5959
auto printHalf = [&](auto low, auto high) {
6060
for(auto ndx = low; ndx < high; ++ndx) {
6161
if(v.intraIndex == ndx) {
62-
ptr += sprintf(ptr, "<");
62+
ptr += snprintf(ptr, bufferSize, "<");
6363
}
64-
ptr += sprintf(ptr, "%02lx", val & 0xFF);
64+
ptr += snprintf(ptr, bufferSize, "%02lx", val & 0xFF);
6565
if(v.intraIndex == ndx) {
66-
ptr += sprintf(ptr, ">");
66+
ptr += snprintf(ptr, bufferSize, ">");
6767
}
6868
val >>= 8;
6969
}
7070
};
7171
printHalf(0, 4);
72-
ptr += sprintf(ptr, "'");
72+
ptr += snprintf(ptr, bufferSize, "'");
7373
printHalf(4, 8);
7474
out << buffer;
7575
return out;

0 commit comments

Comments
 (0)