Skip to content

Commit 872f516

Browse files
authored
allow building when cpp exceptions are disabled (#489)
IXWebSocket needs exceptions support because of the use of stoi. In order to build when cpp exceptions are disabled, we can use strtol.
1 parent 014d43e commit 872f516

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ixwebsocket/IXHttp.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,20 @@ namespace ix
133133
if (headers.find("Content-Length") != headers.end())
134134
{
135135
int contentLength = 0;
136-
try
137136
{
138-
contentLength = std::stoi(headers["Content-Length"]);
137+
const char* p = headers["Content-Length"].c_str();
138+
char* p_end{};
139+
errno = 0;
140+
long val = std::strtol(p, &p_end, 10);
141+
if (p_end == p // invalid argument
142+
|| errno == ERANGE // out of range
143+
|| val < std::numeric_limits<int>::min()
144+
|| val > std::numeric_limits<int>::max()) {
145+
return std::make_tuple(
146+
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
147+
}
148+
contentLength = val;
139149
}
140-
catch (const std::exception&)
141-
{
142-
return std::make_tuple(
143-
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
144-
}
145-
146150
if (contentLength < 0)
147151
{
148152
return std::make_tuple(

0 commit comments

Comments
 (0)