Skip to content

Commit 515630c

Browse files
committed
MB-69779: Remove checked_snprintf
Code refactored to use the modern fmtlib Change-Id: I0f6b1487dad28bdf20bbc9039268527fe751df3c Reviewed-on: https://review.couchbase.org/c/platform/+/237506 Reviewed-by: Mohammad Zaeem <mohammad.zaeem@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 3c9adf4 commit 515630c

6 files changed

Lines changed: 10 additions & 177 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ LIST(APPEND PLATFORM_FILES
221221
src/byte_buffer_dump.cc
222222
src/cb_arena_malloc.cc
223223
src/cb_time.cc
224-
src/checked_snprintf.cc
225224
src/command_line_options_parser.cc
226225
src/crc32c.cc
227226
src/crc32c_private.h
@@ -257,7 +256,6 @@ LIST(APPEND PLATFORM_FILES
257256
include/platform/byte_literals.h
258257
include/platform/cb_allocator.h
259258
include/platform/cb_malloc.h
260-
include/platform/checked_snprintf.h
261259
include/platform/command_line_options_parser.h
262260
include/platform/corestore.h
263261
include/platform/crc32c.h

include/platform/checked_snprintf.h

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/checked_snprintf.cc

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/unit_tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ cb_add_test_executable(platform_unit_tests
99
bitset_test.cc
1010
byte_literals_test.cc
1111
cb_getopt_test.cc
12-
checked_snprintf_test.cc
1312
command_line_options_parser_test.cc
1413
corestore_test.cc
1514
corestore_test.h

tests/unit_tests/checked_snprintf_test.cc

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/unit_tests/sysinfo_test.cc

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,49 @@
88
* the file licenses/APL2.txt.
99
*/
1010
#include <folly/portability/GTest.h>
11-
12-
#include <platform/checked_snprintf.h>
11+
#include <folly/portability/Stdlib.h>
1312
#include <platform/sysinfo.h>
1413

15-
char cpu_count_env_var[256];
16-
1714
TEST(GetAvailableCpu, NoVariable) {
1815
EXPECT_NE(0u, cb::get_available_cpu_count());
1916
}
2017

2118
TEST(GetAvailableCpu, CorrectVariable_ExactNumber) {
22-
checked_snprintf(cpu_count_env_var,
23-
sizeof(cpu_count_env_var),
24-
"COUCHBASE_CPU_COUNT=10000");
25-
putenv(cpu_count_env_var);
19+
setenv("COUCHBASE_CPU_COUNT", "10000", 1);
2620
EXPECT_EQ(10000u, cb::get_available_cpu_count());
2721
}
2822

2923
TEST(GetAvailableCpu, CorrectVariable_LeadingSpace) {
30-
checked_snprintf(cpu_count_env_var,
31-
sizeof(cpu_count_env_var),
32-
"COUCHBASE_CPU_COUNT= 9999");
33-
putenv(cpu_count_env_var);
24+
setenv("COUCHBASE_CPU_COUNT", " 9999", 1);
3425
EXPECT_EQ(9999u, cb::get_available_cpu_count());
3526
}
3627

3728
TEST(GetAvailableCpu, CorrectVariable_TrailingSpace) {
38-
checked_snprintf(cpu_count_env_var,
39-
sizeof(cpu_count_env_var),
40-
"COUCHBASE_CPU_COUNT=9998 ");
41-
putenv(cpu_count_env_var);
29+
setenv("COUCHBASE_CPU_COUNT", "9998 ", 1);
4230
EXPECT_EQ(9998u, cb::get_available_cpu_count());
4331
}
4432

4533
TEST(GetAvailableCpu, CorrectVariable_LeadingTab) {
46-
checked_snprintf(cpu_count_env_var,
47-
sizeof(cpu_count_env_var),
48-
"COUCHBASE_CPU_COUNT=\t9997");
49-
putenv(cpu_count_env_var);
34+
setenv("COUCHBASE_CPU_COUNT", "\t9997", 1);
5035
EXPECT_EQ(9997u, cb::get_available_cpu_count());
5136
}
5237

5338
TEST(GetAvailableCpu, CorrectVariable_TrailigTab) {
54-
checked_snprintf(cpu_count_env_var,
55-
sizeof(cpu_count_env_var),
56-
"COUCHBASE_CPU_COUNT=9996\t");
57-
putenv(cpu_count_env_var);
39+
setenv("COUCHBASE_CPU_COUNT", "9996\t", 1);
5840
EXPECT_EQ(9996u, cb::get_available_cpu_count());
5941
}
6042

6143
TEST(GetAvailableCpu, InvalidValue) {
62-
checked_snprintf(cpu_count_env_var,
63-
sizeof(cpu_count_env_var),
64-
"COUCHBASE_CPU_COUNT=1a");
65-
putenv(cpu_count_env_var);
44+
setenv("COUCHBASE_CPU_COUNT", "1a", 1);
6645
EXPECT_THROW(cb::get_available_cpu_count(), std::logic_error);
6746

68-
checked_snprintf(cpu_count_env_var,
69-
sizeof(cpu_count_env_var),
70-
"COUCHBASE_CPU_COUNT=1 a");
71-
putenv(cpu_count_env_var);
47+
setenv("COUCHBASE_CPU_COUNT", "1 a", 1);
7248
EXPECT_THROW(cb::get_available_cpu_count(), std::logic_error);
7349

74-
checked_snprintf(cpu_count_env_var,
75-
sizeof(cpu_count_env_var),
76-
"COUCHBASE_CPU_COUNT=a1");
77-
putenv(cpu_count_env_var);
50+
setenv("COUCHBASE_CPU_COUNT", "a1", 1);
7851
EXPECT_THROW(cb::get_available_cpu_count(), std::logic_error);
7952

80-
checked_snprintf(cpu_count_env_var,
81-
sizeof(cpu_count_env_var),
82-
"COUCHBASE_CPU_COUNT=a 1");
83-
putenv(cpu_count_env_var);
53+
setenv("COUCHBASE_CPU_COUNT", "a 1", 1);
8454
EXPECT_THROW(cb::get_available_cpu_count(), std::logic_error);
8555
}
8656

0 commit comments

Comments
 (0)