Bug Summary

File:root/firefox-clang/third_party/abseil-cpp/absl/strings/internal/str_format/output.cc
Warning:line 60, column 11
An undefined value may be read from 'errno'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name output.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/security/sandbox/linux -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/security/sandbox/linux -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D NS_NO_XPCOM -I /root/firefox-clang/security/sandbox/linux -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/security/sandbox/linux -I /root/firefox-clang/security/sandbox/linux -I /root/firefox-clang/security/sandbox/chromium-shim -I /root/firefox-clang/security/sandbox/chromium -I /root/firefox-clang/security/sandbox/chromium-shim/base/allocator/partition_allocator/src -I /root/firefox-clang/security/sandbox/chromium/base/allocator/partition_allocator/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/nsprpub -I /root/firefox-clang/mozglue/baseprofiler/core -I /root/firefox-clang/tools/profiler -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -Wno-error=stack-protector -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ /root/firefox-clang/third_party/abseil-cpp/absl/strings/internal/str_format/output.cc
1// Copyright 2017 The Abseil Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "absl/strings/internal/str_format/output.h"
16
17#include <errno(*__errno_location ()).h>
18
19#include <algorithm>
20#include <cstdio>
21#include <cstring>
22
23#include "absl/strings/string_view.h"
24
25namespace absl {
26ABSL_NAMESPACE_BEGIN
27namespace str_format_internal {
28
29namespace {
30struct ClearErrnoGuard {
31 ClearErrnoGuard() : old_value(errno(*__errno_location ())) { errno(*__errno_location ()) = 0; }
32 ~ClearErrnoGuard() {
33 if (!errno(*__errno_location ())) errno(*__errno_location ()) = old_value;
34 }
35 int old_value;
36};
37} // namespace
38
39void BufferRawSink::Write(string_view v) {
40 size_t to_write = std::min(v.size(), size_);
41 if (to_write > 0) {
42 std::memcpy(buffer_, v.data(), to_write);
43 buffer_ += to_write;
44 size_ -= to_write;
45 }
46 total_written_ += v.size();
47}
48
49void FILERawSink::Write(string_view v) {
50 while (!v.empty() && !error_) {
1
Assuming the condition is true
2
Assuming field 'error_' is 0
3
Loop condition is true. Entering loop body
51 // Reset errno to zero in case the libc implementation doesn't set errno
52 // when a failure occurs.
53 ClearErrnoGuard guard;
54
55 if (size_t result = std::fwrite(v.data(), 1, v.size(), output_)) {
4
Assuming that 'fwrite' is successful; 'errno' becomes undefined after the call
5
Assuming 'result' is 0
6
Taking false branch
56 // Some progress was made.
57 count_ += result;
58 v.remove_prefix(result);
59 } else {
60 if (errno(*__errno_location ()) == EINTR4) {
7
An undefined value may be read from 'errno'
61 continue;
62 } else if (errno(*__errno_location ())) {
63 error_ = errno(*__errno_location ());
64 } else if (std::ferror(output_)) {
65 // Non-POSIX compliant libc implementations may not set errno, so we
66 // have check the streams error indicator.
67 error_ = EBADF9;
68 } else {
69 // We're likely on a non-POSIX system that encountered EINTR but had no
70 // way of reporting it.
71 continue;
72 }
73 }
74 }
75}
76
77} // namespace str_format_internal
78ABSL_NAMESPACE_END
79} // namespace absl