mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
fix: [imp] fmt buffer failsafe
This commit is contained in:
parent
8a79e9a86b
commit
6ca5d39a0c
@ -113,6 +113,9 @@ template <typename A /*a fundamental or pointer type*/>
|
|||||||
int sprintf(fmt_context &ctx, span<char const> const &sfmt, A a) {
|
int sprintf(fmt_context &ctx, span<char const> const &sfmt, A a) {
|
||||||
for (int sz = -1;;) {
|
for (int sz = -1;;) {
|
||||||
auto sbuf = ctx.buffer(sz + 1);
|
auto sbuf = ctx.buffer(sz + 1);
|
||||||
|
if (sbuf.size() < (sz + 1)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
sz = std::snprintf(sbuf.data(), sbuf.size(), sfmt.data(), a);
|
sz = std::snprintf(sbuf.data(), sbuf.size(), sfmt.data(), a);
|
||||||
if (sz <= 0) {
|
if (sz <= 0) {
|
||||||
return sz;
|
return sz;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user