Skip to content

Commit fb5a1f0

Browse files
authored
Fixed a mildly annoying compliler warning by making this a static cast instead of an implicit one. (#534)
I also rearranged some of the checks to add better error messages to the 'Content-Length' header check overall.
1 parent 0424295 commit fb5a1f0

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ixwebsocket/IXHttp.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,27 @@ namespace ix
135135
int contentLength = 0;
136136
{
137137
const char* p = headers["Content-Length"].c_str();
138-
char* p_end{};
138+
char* p_end {};
139139
errno = 0;
140140
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()) {
141+
if (p_end == p // invalid argument
142+
|| errno == ERANGE // out of range
143+
)
144+
{
145145
return std::make_tuple(
146146
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
147147
}
148-
contentLength = val;
148+
if (val > std::numeric_limits<int>::max())
149+
{
150+
return std::make_tuple(
151+
false, "Error: 'Content-Length' value was above max", httpRequest);
152+
}
153+
if (val < std::numeric_limits<int>::min())
154+
{
155+
return std::make_tuple(
156+
false, "Error: 'Content-Length' value was below min", httpRequest);
157+
}
158+
contentLength = static_cast<int>(val);
149159
}
150160
if (contentLength < 0)
151161
{

0 commit comments

Comments
 (0)