Skip to content
This repository was archived by the owner on Apr 10, 2021. It is now read-only.

Commit 731b6a9

Browse files
stop crashing from invalid characters
1 parent c576003 commit 731b6a9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

byond-extools/src/core/socket/socket.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool Socket::create(int family, int socktype, int protocol)
5858
return raw_socket != INVALID_SOCKET;
5959
}
6060

61-
bool connect_socket(Socket& socket, const char* port, const char* remote)
61+
bool connect_socket(Socket& socket, const char* port, const char* remote, bool yell = false)
6262
{
6363

6464
struct addrinfo* result = NULL;
@@ -75,14 +75,14 @@ bool connect_socket(Socket& socket, const char* port, const char* remote)
7575
iResult = getaddrinfo(remote, port, &hints, &result);
7676
if (iResult != 0)
7777
{
78-
Core::Alert("getaddrinfo failed with error: " + std::to_string(iResult));
78+
if(yell) Core::Alert("getaddrinfo failed with error: " + std::to_string(iResult));
7979
return false;
8080
}
8181

8282
// Create a SOCKET for connecting to server
8383
if (!socket.create(result->ai_family, result->ai_socktype, result->ai_protocol))
8484
{
85-
Core::Alert("socket failed with error: " + std::to_string(WSAGetLastError()));
85+
if(yell) Core::Alert("socket failed with error: " + std::to_string(WSAGetLastError()));
8686
freeaddrinfo(result);
8787
return false;
8888
}
@@ -91,7 +91,7 @@ bool connect_socket(Socket& socket, const char* port, const char* remote)
9191
iResult = ::connect(socket.raw(), result->ai_addr, (int)result->ai_addrlen);
9292
if (iResult == SOCKET_ERROR)
9393
{
94-
Core::Alert("connect failed with error: " + std::to_string(WSAGetLastError()));
94+
if(yell) Core::Alert("connect failed with error: " + std::to_string(WSAGetLastError()));
9595
freeaddrinfo(result);
9696
socket.close();
9797
return false;
@@ -176,7 +176,7 @@ bool JsonStream::connect(const char* port, const char* remote)
176176
return false;
177177
}
178178

179-
return connect_socket(socket, port, remote);
179+
return connect_socket(socket, port, remote, true);
180180
}
181181

182182
bool JsonStream::send(const char* type, nlohmann::json content)
@@ -190,7 +190,7 @@ bool JsonStream::send(const char* type, nlohmann::json content)
190190

191191
bool JsonStream::send(nlohmann::json j)
192192
{
193-
std::string data = j.dump();
193+
std::string data = j.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
194194
data.push_back(0);
195195
while (!data.empty())
196196
{

byond-extools/src/extended_profiling/normal_profiling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ trvh dump_all_profiles(unsigned int args_len, Value* args, Value src)
5252
interresult.push_back(j);
5353
}
5454
nlohmann::json jresult = interresult;
55-
std::string result = jresult.dump();
55+
std::string result = jresult.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
5656
auto end = std::chrono::high_resolution_clock::now();
5757
unsigned long long milis = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
5858
//Core::Alert(std::to_string(milis));

0 commit comments

Comments
 (0)