Skip to content

Commit 1d06624

Browse files
committed
Unset /D_CRT_SECURE_NO_WARNINGS
- Also localize DISABLE_DEPRECATED_WARNING so that we catch other deprecations
1 parent d40069a commit 1d06624

9 files changed

+30
-22
lines changed

include/simdjson.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ SIMDJSON_PUSH_DISABLE_WARNINGS
1414
#if defined(_MSC_VER) && defined(__clang__)
1515
SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
1616
#endif
17-
SIMDJSON_DISABLE_DEPRECATED_WARNING
1817

1918
// Public API
2019
#include "simdjson/simdjson_version.h"

include/simdjson/inline/document.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,11 @@ inline bool parser::dump_raw_tape(std::ostream &os) const noexcept {
339339

340340
inline simdjson_result<size_t> parser::read_file(const std::string &path) noexcept {
341341
// Open the file
342+
SIMDJSON_PUSH_DISABLE_WARNINGS
343+
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
342344
std::FILE *fp = std::fopen(path.c_str(), "rb");
345+
SIMDJSON_POP_DISABLE_WARNINGS
346+
343347
if (fp == nullptr) {
344348
return IO_ERROR;
345349
}

include/simdjson/inline/padded_string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ inline padded_string::operator std::string_view() const { return std::string_vie
102102

103103
inline simdjson_result<padded_string> padded_string::load(const std::string &filename) noexcept {
104104
// Open the file
105+
SIMDJSON_PUSH_DISABLE_WARNINGS
106+
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
105107
std::FILE *fp = std::fopen(filename.c_str(), "rb");
108+
SIMDJSON_POP_DISABLE_WARNINGS
109+
106110
if (fp == nullptr) {
107111
return IO_ERROR;
108112
}

include/simdjson/inline/parsedjson_iterator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
namespace simdjson {
77

8+
// VS2017 reports deprecated warnings when you define a deprecated class's methods.
9+
SIMDJSON_PUSH_DISABLE_WARNINGS
10+
SIMDJSON_DISABLE_DEPRECATED_WARNING
11+
12+
// Because of template weirdness, the actual class definition is inline in the document class
13+
814
WARN_UNUSED bool dom::parser::Iterator::is_ok() const {
915
return location < tape_length;
1016
}
@@ -471,6 +477,8 @@ bool dom::parser::Iterator::relative_move_to(const char *pointer,
471477
return found;
472478
}
473479

480+
SIMDJSON_POP_DISABLE_WARNINGS
481+
474482
} // namespace simdjson
475483

476484
#endif // SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H

simdjson-flags.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_library(simdjson-internal-flags INTERFACE)
3939
target_link_libraries(simdjson-internal-flags INTERFACE simdjson-flags)
4040

4141
if(MSVC)
42-
target_compile_options(simdjson-internal-flags INTERFACE /nologo /D_CRT_SECURE_NO_WARNINGS)
42+
target_compile_options(simdjson-internal-flags INTERFACE /nologo)
4343
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl)
4444
else()
4545
target_compile_options(simdjson-internal-flags INTERFACE -fPIC)

src/implementation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ const implementation *available_implementation_list::detect_best_supported() con
122122
}
123123

124124
const implementation *detect_best_supported_implementation_on_first_use::set_best() const noexcept {
125+
SIMDJSON_PUSH_DISABLE_WARNINGS
126+
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
125127
char *force_implementation_name = getenv("SIMDJSON_FORCE_IMPLEMENTATION");
128+
SIMDJSON_POP_DISABLE_WARNINGS
129+
126130
if (force_implementation_name) {
127131
auto force_implementation = available_implementations[force_implementation_name];
128132
if (!force_implementation) {

src/simdjson.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ SIMDJSON_PUSH_DISABLE_WARNINGS
44
#if defined(SIMDJSON_CLANG_VISUAL_STUDIO)
55
SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
66
#endif
7-
SIMDJSON_DISABLE_DEPRECATED_WARNING
87

98
#include "error.cpp"
109
#include "implementation.cpp"

tests/jsoncheck.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,11 @@ bool validate(const char *dirname) {
5555
if (has_extension(name, extension)) {
5656
printf("validating: file %s ", name);
5757
fflush(nullptr);
58-
size_t filelen = strlen(name);
59-
char *fullpath = static_cast<char *>(malloc(dirlen + filelen + 1 + 1));
60-
strcpy(fullpath, dirname);
61-
if (needsep) {
62-
fullpath[dirlen] = '/';
63-
strcpy(fullpath + dirlen + 1, name);
64-
} else {
65-
strcpy(fullpath + dirlen, name);
66-
}
58+
size_t namelen = strlen(name);
59+
size_t fullpathlen = dirlen + 1 + namelen + 1;
60+
char *fullpath = static_cast<char *>(malloc(fullpathlen));
61+
snprintf(fullpath, fullpathlen, "%s%s%s", dirname, needsep ? "/" : "", name);
62+
6763
auto [p, error] = simdjson::padded_string::load(fullpath);
6864
if (error) {
6965
std::cerr << "Could not load the file " << fullpath << std::endl;

tests/parse_many_test.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,10 @@ bool validate(const char *dirname) {
6363
/* Finding the file path */
6464
printf("validating: file %s ", name);
6565
fflush(nullptr);
66-
size_t filelen = strlen(name);
67-
char *fullpath = static_cast<char *>(malloc(dirlen + filelen + 1 + 1));
68-
strcpy(fullpath, dirname);
69-
if (needsep) {
70-
fullpath[dirlen] = '/';
71-
strcpy(fullpath + dirlen + 1, name);
72-
} else {
73-
strcpy(fullpath + dirlen, name);
74-
}
75-
66+
size_t namelen = strlen(name);
67+
size_t fullpathlen = dirlen + 1 + namelen + 1;
68+
char *fullpath = static_cast<char *>(malloc(fullpathlen));
69+
snprintf(fullpath, fullpathlen, "%s%s%s", dirname, needsep ? "/" : "", name);
7670

7771
/* The actual test*/
7872
auto [json, error] = simdjson::padded_string::load(fullpath);

0 commit comments

Comments
 (0)