mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-31 18:31:04 +00:00
Fix Irrlicht snprintf problems and UB in my_string_to_double
This commit is contained in:
parent
baaab310fe
commit
079169612d
4 changed files with 6 additions and 12 deletions
|
@ -43,14 +43,8 @@ typedef float f32;
|
|||
/** This is a typedef for double, it ensures portability of the engine. */
|
||||
typedef double f64;
|
||||
|
||||
//! Defines for snprintf_irr because snprintf method does not match the ISO C
|
||||
//! standard on Windows platforms.
|
||||
//! We want int snprintf_irr(char *str, size_t size, const char *format, ...);
|
||||
#if defined(_MSC_VER)
|
||||
#define snprintf_irr sprintf_s
|
||||
#else
|
||||
//! Note: cannot assume that positional arguments are supported (not on Windows)
|
||||
#define snprintf_irr snprintf
|
||||
#endif // _MSC_VER
|
||||
|
||||
//! Type name for character type used by the file system (legacy).
|
||||
typedef char fschar_t;
|
||||
|
|
|
@ -164,7 +164,7 @@ public:
|
|||
Size = OriginalSize;
|
||||
|
||||
if (core::min_(Size.Width, Size.Height) == 0 || core::max_(Size.Width, Size.Height) > Driver->MaxTextureSize) {
|
||||
char buf[64];
|
||||
char buf[32];
|
||||
snprintf_irr(buf, sizeof(buf), "%dx%d", Size.Width, Size.Height);
|
||||
os::Printer::log("Invalid size for render target", buf, ELL_ERROR);
|
||||
return;
|
||||
|
@ -187,7 +187,7 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
char lbuf[100];
|
||||
char lbuf[200];
|
||||
snprintf_irr(lbuf, sizeof(lbuf),
|
||||
"COpenGLCoreTexture: RTT Type = %d Size = %dx%d (S:%d) ColorFormat = %s -> %#06x %#06x %#06x%s",
|
||||
(int)Type, Size.Width, Size.Height, (int)MSAA, ColorFormatName(ColorFormat),
|
||||
|
@ -484,7 +484,7 @@ protected:
|
|||
Size = OriginalSize;
|
||||
|
||||
if (Size.Width == 0 || Size.Height == 0) {
|
||||
char buf[64];
|
||||
char buf[32];
|
||||
snprintf_irr(buf, sizeof(buf), "%dx%d", Size.Width, Size.Height);
|
||||
os::Printer::log("Invalid size of image for texture", buf, ELL_ERROR);
|
||||
return;
|
||||
|
|
|
@ -139,7 +139,7 @@ void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum s
|
|||
ll = ELL_ERROR;
|
||||
else if (severity == GL_DEBUG_SEVERITY_MEDIUM)
|
||||
ll = ELL_WARNING;
|
||||
char buf[300];
|
||||
char buf[512];
|
||||
snprintf_irr(buf, sizeof(buf), "%04x %04x %.*s", source, type, length, message);
|
||||
os::Printer::log("GL", buf, ll);
|
||||
}
|
||||
|
|
|
@ -1087,7 +1087,7 @@ std::optional<double> my_string_to_double(const std::string &s)
|
|||
char *end = nullptr;
|
||||
// Note: this also supports hexadecimal notation like "0x1.0p+1"
|
||||
double number = std::strtod(s.c_str(), &end);
|
||||
if (end != &*s.end())
|
||||
if (end && *end != '\0')
|
||||
return std::nullopt;
|
||||
return number;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue