Skip to content

Commit b60d2d5

Browse files
authored
Merge pull request #1184 from CrowCpp/alert-fix-1
Prevent possible integer overflow on multiplication
2 parents 8a87cfd + 6361f4a commit b60d2d5

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

include/crow/json.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,14 +1862,14 @@ namespace crow // NOTE: Already documented in "crow/app.h"
18621862
out.push_back('"');
18631863
}
18641864

1865-
inline void dump_indentation_part(std::string& out, const int indent, const char separator, const int indent_level) const
1865+
inline void dump_indentation_part(std::string& out, const size_t indent, const char separator, const int indent_level) const
18661866
{
18671867
out.push_back('\n');
18681868
out.append(indent_level * indent, separator);
18691869
}
18701870

18711871

1872-
inline void dump_internal(const wvalue& v, std::string& out, const int indent, const char separator, const int indent_level = 0) const
1872+
inline void dump_internal(const wvalue& v, std::string& out, const size_t indent, const char separator, const int indent_level = 0) const
18731873
{
18741874
switch (v.t_)
18751875
{
@@ -1965,7 +1965,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
19651965
{
19661966
out.push_back('[');
19671967

1968-
if (indent >= 0)
1968+
if (indent !=std::string::npos)
19691969
{
19701970
dump_indentation_part(out, indent, separator, indent_level + 1);
19711971
}
@@ -1979,7 +1979,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
19791979
{
19801980
out.push_back(',');
19811981

1982-
if (indent >= 0)
1982+
if (indent != std::string::npos)
19831983
{
19841984
dump_indentation_part(out, indent, separator, indent_level + 1);
19851985
}
@@ -1989,7 +1989,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
19891989
}
19901990
}
19911991

1992-
if (indent >= 0)
1992+
if (indent !=std::string::npos)
19931993
{
19941994
dump_indentation_part(out, indent, separator, indent_level);
19951995
}
@@ -2001,7 +2001,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
20012001
{
20022002
out.push_back('{');
20032003

2004-
if (indent >= 0)
2004+
if (indent != std::string::npos)
20052005
{
20062006
dump_indentation_part(out, indent, separator, indent_level + 1);
20072007
}
@@ -2014,7 +2014,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
20142014
if (!first)
20152015
{
20162016
out.push_back(',');
2017-
if (indent >= 0)
2017+
if (indent != std::string::npos)
20182018
{
20192019
dump_indentation_part(out, indent, separator, indent_level + 1);
20202020
}
@@ -2023,7 +2023,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
20232023
dump_string(kv.first, out);
20242024
out.push_back(':');
20252025

2026-
if (indent >= 0)
2026+
if (indent != std::string::npos)
20272027
{
20282028
out.push_back(' ');
20292029
}
@@ -2032,7 +2032,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
20322032
}
20332033
}
20342034

2035-
if (indent >= 0)
2035+
if (indent != std::string::npos)
20362036
{
20372037
dump_indentation_part(out, indent, separator, indent_level);
20382038
}
@@ -2048,7 +2048,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
20482048
}
20492049

20502050
public:
2051-
std::string dump(const int indent, const char separator = ' ') const
2051+
std::string dump(const size_t indent, const char separator = ' ') const
20522052
{
20532053
std::string ret;
20542054
ret.reserve(estimate_length());
@@ -2058,7 +2058,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
20582058

20592059
std::string dump() const override
20602060
{
2061-
static constexpr int DontIndent = -1;
2061+
static constexpr size_t DontIndent = std::string::npos;
20622062

20632063
return dump(DontIndent);
20642064
}

0 commit comments

Comments
 (0)