Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp
Warning:line 89, column 12
Value stored to 'rv' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_layout_style3.cpp -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=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -resource-dir /usr/lib/llvm-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/layout/base -I /var/lib/jenkins/workspace/firefox-scan-build/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/layout/xul -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/html -I /var/lib/jenkins/workspace/firefox-scan-build/dom/xul -I /var/lib/jenkins/workspace/firefox-scan-build/image -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-error=deprecated -Wno-error=deprecated-anon-enum-enum-conversion -Wno-error=deprecated-enum-enum-conversion -Wno-error=deprecated-pragma -Wno-error=deprecated-this-capture -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 -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-03-10-033526-22998-1 -x c++ Unified_cpp_layout_style3.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "mozilla/css/StreamLoader.h"
8
9#include "mozilla/Encoding.h"
10#include "mozilla/TaskQueue.h"
11#include "nsContentUtils.h"
12#include "nsIChannel.h"
13#include "nsIInputStream.h"
14#include "nsIThreadRetargetableRequest.h"
15#include "nsIStreamTransportService.h"
16#include "nsNetCID.h"
17#include "nsServiceManagerUtils.h"
18
19namespace mozilla::css {
20
21StreamLoader::StreamLoader(SheetLoadData& aSheetLoadData)
22 : mSheetLoadData(&aSheetLoadData), mStatus(NS_OK) {}
23
24StreamLoader::~StreamLoader() {
25#ifdef NIGHTLY_BUILD1
26 MOZ_RELEASE_ASSERT(mOnStopRequestCalled || mChannelOpenFailed)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnStopRequestCalled || mChannelOpenFailed)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mOnStopRequestCalled || mChannelOpenFailed))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mOnStopRequestCalled || mChannelOpenFailed"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 26); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mOnStopRequestCalled || mChannelOpenFailed"
")"); do { *((volatile int*)__null) = 26; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
27#endif
28}
29
30NS_IMPL_ISUPPORTS(StreamLoader, nsIStreamListener,MozExternalRefCountType StreamLoader::AddRef(void) { static_assert
(!std::is_destructible_v<StreamLoader>, "Reference-counted class "
"StreamLoader" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
31; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 31; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt
; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)(
sizeof(*this))); return count; } MozExternalRefCountType StreamLoader
::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0"
" (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 31
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 31; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); const char* const nametmp
= "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease(
(this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete
(this); return 0; } return count; } nsresult StreamLoader::QueryInterface
(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIThreadRetargetableStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert((
sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
31 nsIThreadRetargetableStreamListener)MozExternalRefCountType StreamLoader::AddRef(void) { static_assert
(!std::is_destructible_v<StreamLoader>, "Reference-counted class "
"StreamLoader" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
31; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 31; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt
; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)(
sizeof(*this))); return count; } MozExternalRefCountType StreamLoader
::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0"
" (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 31
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 31; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); const char* const nametmp
= "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease(
(this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete
(this); return 0; } return count; } nsresult StreamLoader::QueryInterface
(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 31); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIThreadRetargetableStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert((
sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
32
33/* nsIRequestObserver implementation */
34NS_IMETHODIMPnsresult
35StreamLoader::OnStartRequest(nsIRequest* aRequest) {
36 MOZ_ASSERT(aRequest)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRequest)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aRequest))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aRequest", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 36); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest" ")"
); do { *((volatile int*)__null) = 36; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
37 mSheetLoadData->NotifyStart(aRequest);
38
39 // It's kinda bad to let Web content send a number that results
40 // in a potentially large allocation directly, but efficiency of
41 // compression bombs is so great that it doesn't make much sense
42 // to require a site to send one before going ahead and allocating.
43 if (nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest)) {
44 int64_t length;
45 nsresult rv = channel->GetContentLength(&length);
46 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && length > 0) {
47 CheckedInt<nsACString::size_type> checkedLength(length);
48 if (!checkedLength.isValid()) {
49 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
50 }
51 if (!mBytes.SetCapacity(checkedLength.value(), fallible)) {
52 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
53 }
54 }
55 }
56 if (nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest)) {
57 nsCOMPtr<nsIEventTarget> sts =
58 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1");
59 RefPtr queue =
60 TaskQueue::Create(sts.forget(), "css::StreamLoader Delivery Queue");
61 rr->RetargetDeliveryTo(queue);
62 }
63
64 mSheetLoadData->mExpirationTime = [&] {
65 auto info = nsContentUtils::GetSubresourceCacheValidationInfo(
66 aRequest, mSheetLoadData->mURI);
67
68 // For now, we never cache entries that we have to revalidate, or whose
69 // channel don't support caching.
70 if (info.mMustRevalidate || !info.mExpirationTime) {
71 return nsContentUtils::SecondsFromPRTime(PR_Now()) - 1;
72 }
73 return *info.mExpirationTime;
74 }();
75
76 return NS_OK;
77}
78
79NS_IMETHODIMPnsresult
80StreamLoader::CheckListenerChain() { return NS_OK; }
81
82NS_IMETHODIMPnsresult
83StreamLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
84#ifdef NIGHTLY_BUILD1
85 MOZ_RELEASE_ASSERT(!mOnStopRequestCalled)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mOnStopRequestCalled)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mOnStopRequestCalled))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopRequestCalled"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 85); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "!mOnStopRequestCalled"
")"); do { *((volatile int*)__null) = 85; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
86 mOnStopRequestCalled = true;
87#endif
88
89 nsresult rv = mStatus;
Value stored to 'rv' during its initialization is never read
90 // Decoded data
91 nsCString utf8String;
92 {
93 // Hold the nsStringBuffer for the bytes from the stack to ensure release
94 // no matter which return branch is taken.
95 nsCString bytes = std::move(mBytes);
96
97 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
98
99 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
100 mSheetLoadData->VerifySheetReadyToParse(mStatus, ""_ns, ""_ns, channel);
101 return mStatus;
102 }
103
104 rv = mSheetLoadData->VerifySheetReadyToParse(aStatus, mBOMBytes, bytes,
105 channel);
106 if (rv != NS_OK_PARSE_SHEET) {
107 return rv;
108 }
109
110 // BOM detection generally happens during the write callback, but that won't
111 // have happened if fewer than three bytes were received.
112 if (mEncodingFromBOM.isNothing()) {
113 HandleBOM();
114 MOZ_ASSERT(mEncodingFromBOM.isSome())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mEncodingFromBOM.isSome())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mEncodingFromBOM.isSome())))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("mEncodingFromBOM.isSome()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 114); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isSome()"
")"); do { *((volatile int*)__null) = 114; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
115 }
116
117 // The BOM handling has happened, but we still may not have an encoding if
118 // there was no BOM. Ensure we have one.
119 const Encoding* encoding = mEncodingFromBOM.value();
120 if (!encoding) {
121 // No BOM
122 encoding = mSheetLoadData->DetermineNonBOMEncoding(bytes, channel);
123 }
124 mSheetLoadData->mEncoding = encoding;
125
126 size_t validated = 0;
127 if (encoding == UTF_8_ENCODING) {
128 validated = Encoding::UTF8ValidUpTo(bytes);
129 }
130
131 if (validated == bytes.Length()) {
132 // Either this is UTF-8 and all valid, or it's not UTF-8 but is an empty
133 // string. This assumes that an empty string in any encoding decodes to
134 // empty string, which seems like a plausible assumption.
135 utf8String = std::move(bytes);
136 } else {
137 rv = encoding->DecodeWithoutBOMHandling(bytes, utf8String, validated);
138 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 138); return rv; } } while (false)
;
139 }
140 } // run destructor for `bytes`
141
142 // For reasons I don't understand, factoring the below lines into
143 // a method on SheetLoadData resulted in a linker error. Hence,
144 // accessing fields of mSheetLoadData from here.
145 mSheetLoadData->mLoader->ParseSheet(utf8String, *mSheetLoadData,
146 Loader::AllowAsyncParse::Yes);
147
148 return NS_OK;
149}
150
151/* nsIStreamListener implementation */
152NS_IMETHODIMPnsresult
153StreamLoader::OnDataAvailable(nsIRequest*, nsIInputStream* aInputStream,
154 uint64_t, uint32_t aCount) {
155 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
156 return mStatus;
157 }
158 uint32_t dummy;
159 return aInputStream->ReadSegments(WriteSegmentFun, this, aCount, &dummy);
160}
161
162NS_IMETHODIMPnsresult
163StreamLoader::OnDataFinished(nsresult aStatus) { return NS_OK; }
164
165void StreamLoader::HandleBOM() {
166 MOZ_ASSERT(mEncodingFromBOM.isNothing())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mEncodingFromBOM.isNothing())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mEncodingFromBOM.isNothing()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mEncodingFromBOM.isNothing()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 166); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isNothing()"
")"); do { *((volatile int*)__null) = 166; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
167 MOZ_ASSERT(mBytes.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mBytes.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mBytes.IsEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mBytes.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 167); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBytes.IsEmpty()"
")"); do { *((volatile int*)__null) = 167; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
168
169 auto [encoding, bomLength] = Encoding::ForBOM(mBOMBytes);
170 mEncodingFromBOM.emplace(encoding); // Null means no BOM.
171
172 // BOMs are three bytes at most, but may be fewer. Copy over anything
173 // that wasn't part of the BOM to mBytes. Note that we need to track
174 // any BOM bytes as well for SRI handling.
175 mBytes.Append(Substring(mBOMBytes, bomLength));
176 mBOMBytes.Truncate(bomLength);
177}
178
179nsresult StreamLoader::WriteSegmentFun(nsIInputStream*, void* aClosure,
180 const char* aSegment, uint32_t,
181 uint32_t aCount, uint32_t* aWriteCount) {
182 *aWriteCount = 0;
183 StreamLoader* self = static_cast<StreamLoader*>(aClosure);
184 if (NS_FAILED(self->mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(self->mStatus))
, 0)))
) {
185 return self->mStatus;
186 }
187
188 // If we haven't done BOM detection yet, divert bytes into the special buffer.
189 if (self->mEncodingFromBOM.isNothing()) {
190 size_t bytesToCopy = std::min<size_t>(3 - self->mBOMBytes.Length(), aCount);
191 self->mBOMBytes.Append(aSegment, bytesToCopy);
192 aSegment += bytesToCopy;
193 *aWriteCount += bytesToCopy;
194 aCount -= bytesToCopy;
195
196 if (self->mBOMBytes.Length() == 3) {
197 self->HandleBOM();
198 } else {
199 return NS_OK;
200 }
201 }
202
203 if (!self->mBytes.Append(aSegment, aCount, fallible)) {
204 self->mBytes.Truncate();
205 return (self->mStatus = NS_ERROR_OUT_OF_MEMORY);
206 }
207
208 *aWriteCount += aCount;
209 return NS_OK;
210}
211
212} // namespace mozilla::css