Skip to content

Commit

Permalink
fix warning on non MS systems for using sprintf instead of snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
gittiver committed Dec 25, 2022
1 parent 209f5ec commit a77d7bd
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions include/crow/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -1830,19 +1830,18 @@ namespace crow
CROW_LOG_WARNING << "Invalid JSON value detected (" << v.num.d << "), value set to null";
break;
}
#ifdef _MSC_VER
#define MSC_COMPATIBLE_SPRINTF(BUFFER_PTR, FORMAT_PTR, VALUE) sprintf_s((BUFFER_PTR), 128, (FORMAT_PTR), (VALUE))
#else
#define MSC_COMPATIBLE_SPRINTF(BUFFER_PTR, FORMAT_PTR, VALUE) sprintf((BUFFER_PTR), (FORMAT_PTR), (VALUE))
#endif
enum
{
start,
decp, // Decimal point
zero
} f_state;
char outbuf[128];
MSC_COMPATIBLE_SPRINTF(outbuf, "%f", v.num.d);
#ifdef _MSC_VER
sprintf_s(outbuf, sizeof(outbuf), "%f", v.num.d);
#else
snprintf(outbuf, sizeof(outbuf), "%f", v.num.d);
#endif
char *p = &outbuf[0], *o = nullptr; // o is the position of the first trailing 0
f_state = start;
while (*p != '\0')
Expand Down Expand Up @@ -1882,7 +1881,6 @@ namespace crow
if (o != nullptr) // if any trailing 0s are found, terminate the string where they begin
*o = '\0';
out += outbuf;
#undef MSC_COMPATIBLE_SPRINTF
}
else if (v.nt == num_type::Signed_integer)
{
Expand Down

0 comments on commit a77d7bd

Please sign in to comment.