diff options
author | Baranov Victor <bar.victor.2002@gmail.com> | 2025-06-30 22:43:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-30 22:43:47 +0300 |
commit | 96b9b2e21de466490ba733a23e8bb6cbd39ad58c (patch) | |
tree | 46e0054991a34858399896b7df8ddceec46ced64 /clang/lib/Sema/SemaChecking.cpp | |
parent | 90da61634a4accc9869b4e1cb1ac3736158c33e6 (diff) | |
download | llvm-96b9b2e21de466490ba733a23e8bb6cbd39ad58c.zip llvm-96b9b2e21de466490ba733a23e8bb6cbd39ad58c.tar.gz llvm-96b9b2e21de466490ba733a23e8bb6cbd39ad58c.tar.bz2 |
[Clang] Fix '-Wformat-overflow' FP when floats had field-width and plus prefix (#144274)
If field width is specified, the sign/space is already accounted for
within the field width, so no additional size is needed.
Fixes https://github.com/llvm/llvm-project/issues/143951.
---------
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 51b22a5..dd5b710 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1012,7 +1012,10 @@ public: break; } - Size += FS.hasPlusPrefix() || FS.hasSpacePrefix(); + // If field width is specified, the sign/space is already accounted for + // within the field width, so no additional size is needed. + if ((FS.hasPlusPrefix() || FS.hasSpacePrefix()) && FieldWidth == 0) + Size += 1; if (FS.hasAlternativeForm()) { switch (FS.getConversionSpecifier().getKind()) { |