Compare commits

...
3 Commits
Author SHA1 Message Date
Moonchild 44d17e4ee7 Replace strnlen with memchr. See code comment. 2026-08-15 10:19:41 +02:00
Moonchild 26cc7c3126 Revert "Refactor string utils in MFBT."
This reverts commit cea1b66ba5.
2026-08-15 09:49:46 +02:00
Moonchild cea1b66ba5 Refactor string utils in MFBT.
This adds an Apple carveout for strnlen for OS X < 10.7 and renames the
ToString.h header to StringUtils.h to better reflect the more generic
collection of functions in it, instead of a 1-file-1-method header.
2026-08-13 16:42:35 +02:00
+7 -1
View File
@@ -312,7 +312,13 @@ cvt_s(SprintfState* ss, const char* s, int width, int prec, int flags)
s = generic_null_str(s);
// Limit string length by precision value
size_t slen = strnlen(s, size_t(prec));
// We'd want to use strnlen() here, but it is not supported by all targets
// (Most notably old OS X), so use memchr instead.
// Replace with `size_t slen = strnlen(s, size_t(prec));` once we no longer
// need to cater to this.
const char* sptr = (const char*)memchr(s, 0, size_t(prec));
size_t slen = sptr ? sptr - s : size_t(prec);
if (slen > INT_MAX) {
return false;
}