dep/reshadefx: Avoid snprintf() when writing float constants

Locale-specific, causes breakage on some systems.
This commit is contained in:
Stenzek 2024-07-29 20:38:32 +10:00
parent e0911d7f54
commit 2d2bc93ada
No known key found for this signature in database
2 changed files with 18 additions and 6 deletions

View file

@ -9,6 +9,9 @@
#include <cstdio> // snprintf
#include <cassert>
#include <algorithm> // std::find_if, std::max
#include <iomanip>
#include <locale>
#include <sstream>
#include <unordered_set>
using namespace reshadefx;
@ -360,9 +363,12 @@ private:
s += std::signbit(data.as_float[i]) ? "1.0/0.0/*inf*/" : "-1.0/0.0/*-inf*/";
break;
}
char temp[64]; // Will be null-terminated by snprintf
std::snprintf(temp, sizeof(temp), "%1.8e", data.as_float[i]);
s += temp;
{
std::ostringstream ss;
ss.imbue(std::locale::classic());
ss << std::fixed << data.as_float[i];
s += ss.str();
}
break;
default:
assert(false);

View file

@ -11,6 +11,9 @@
#include <cassert>
#include <cstring> // stricmp
#include <algorithm> // std::find_if, std::max
#include <iomanip>
#include <locale>
#include <sstream>
using namespace reshadefx;
@ -339,9 +342,12 @@ private:
s += std::signbit(data.as_float[i]) ? "1.#INF" : "-1.#INF";
break;
}
char temp[64]; // Will be null-terminated by snprintf
std::snprintf(temp, sizeof(temp), "%1.8e", data.as_float[i]);
s += temp;
{
std::ostringstream ss;
ss.imbue(std::locale::classic());
ss << std::fixed << data.as_float[i];
s += ss.str();
}
break;
default:
assert(false);