mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Fix a buffer underflow in the Center function from the string library.
This commit is contained in:
parent
159e2f5929
commit
ea9f60e32c
@ -410,10 +410,12 @@ CSStr CenterStr(CSStr s, SQChar f, Uint32 w)
|
|||||||
{
|
{
|
||||||
// Calculate the string length
|
// Calculate the string length
|
||||||
const Uint32 n = std::strlen(s);
|
const Uint32 n = std::strlen(s);
|
||||||
|
// Calculate the insert position
|
||||||
|
const Int32 p = ((w/2) - (n/2));
|
||||||
// Insert only the fill character first
|
// Insert only the fill character first
|
||||||
std::memset(b.Data(), f, w);
|
std::memset(b.Data(), f, w);
|
||||||
// Overwrite with the specified string
|
// Overwrite with the specified string
|
||||||
std::strncpy(b.Data() + ((w/2) - (n/2)), s, n);
|
std::strncpy(b.Data() + (p < 0 ? 0 : p), s, n);
|
||||||
}
|
}
|
||||||
// End the resulted string
|
// End the resulted string
|
||||||
b.At(w) = '\0';
|
b.At(w) = '\0';
|
||||||
|
Loading…
Reference in New Issue
Block a user