fix null pointer arithmetic for %s with precision in vprintf #5001
All Vouch review confidence checks passed
Residual risk 0.13 = Change Risk (0.32) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.32 · 129 lines diff across 1 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.291
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5001"
general
weight: 0.35
aizu-m
UBSan, running printf-test under clang -fsanitize=undefined:
include/fmt/printf.h:497:26: runtime error: applying non-zero offset 3 to null pointer
fmt::sprintf("%.3s", (const char*)nullptr)reaches it. The plain%snull path already prints(null), but once a precision is presentdetail::vprintfenters the cstring-truncation block and evaluatesstr + specs.precision, thenstd::findover that range, whilestris still null. That runs beforeprintf_arg_formatter's null check, so the(null)output is never reached and the pointer arithmetic is undefined behaviour.Guarded the block with
if (str). For a null argument it now follows glibc, which writes(null)only when the precision is unset or at least 6 and an empty string otherwise. So%.0sand%.3sgive""and%.6sgives(null), with width padding as usual. Valid strings are unaffected.Added those cases to
printf_test.string. They fail on the previous revision and pass now, with the rest of the suite clean under ASan and UBSan.