StrPatchFmt
Description
Patch existing bytes in out starting at offset. The formatted content must fit within the current out->length; the buffer is not grown. Useful for back-patching placeholder fields after later data has been computed.
Success
Bytes [offset, offset + written) of out are replaced; returns true.
Failure
Returns false if the formatted output would extend past out->length. out is left unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.Write.c:788:
StrAppendFmt(&s, "AAAAAAAA");
size before_length = s.length;
bool ok = StrPatchFmt(&s, 2, "{}", LVAL(1234));
ok = ok && s.length == before_length;
ok = ok && s.data[0] == 'A' && s.data[1] == 'A';- In
Io.Write.c:795:
// Patch that would extend past the end must fail.
ok = ok && !StrPatchFmt(&s, 6, "{}", LVAL(9999));
ok = ok && s.length == before_length;
ok = ok && s.data[6] == 'A' && s.data[7] == 'A';- In
Io.c:516:
if (offset > o->length || tmp.length > o->length - offset) {
LOG_ERROR(
"StrPatchFmt: write of {} bytes at offset {} exceeds str length {}",
tmp.length,
offset,
Last updated on