Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp
Warning:line 131, 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_style4.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-19/lib/clang/19 -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 MOZ_SUPPORT_LEAKCHECKING -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/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/protocol/http -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/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-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 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -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-09-22-115206-3586786-1 -x c++ Unified_cpp_layout_style4.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#include "mozilla/StaticPrefs_network.h"
9#include "mozilla/Encoding.h"
10#include "mozilla/glean/GleanMetrics.h"
11#include "mozilla/TaskQueue.h"
12#include "mozilla/dom/CacheExpirationTime.h"
13#include "nsContentUtils.h"
14#include "nsIAsyncVerifyRedirectCallback.h"
15#include "nsIChannel.h"
16#include "nsIInputStream.h"
17#include "nsIThreadRetargetableRequest.h"
18#include "nsIStreamTransportService.h"
19#include "nsNetCID.h"
20#include "nsNetUtil.h"
21#include "nsProxyRelease.h"
22#include "nsServiceManagerUtils.h"
23
24namespace mozilla::css {
25
26StreamLoader::StreamLoader(SheetLoadData& aSheetLoadData)
27 : mSheetLoadData(&aSheetLoadData),
28 mStatus(NS_OK),
29 mMainThreadSheetLoadData(new nsMainThreadPtrHolder<SheetLoadData>(
30 "StreamLoader::SheetLoadData", mSheetLoadData, false)) {}
31
32StreamLoader::~StreamLoader() {
33#ifdef NIGHTLY_BUILD1
34 MOZ_RELEASE_ASSERT(mOnStopProcessingDone || mChannelOpenFailed)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnStopProcessingDone || mChannelOpenFailed)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mOnStopProcessingDone || mChannelOpenFailed))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mOnStopProcessingDone || mChannelOpenFailed"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 34); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mOnStopProcessingDone || mChannelOpenFailed"
")"); do { *((volatile int*)__null) = 34; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
35#endif
36}
37
38NS_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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
40; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 40; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 40
; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 40; __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"
, 40); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 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, nsIChannelEventSink>, int32_t( reinterpret_cast
<char*>(static_cast<nsIChannelEventSink*>((StreamLoader
*)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000
))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor
>, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor
*>((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; }
39 nsIThreadRetargetableStreamListener, nsIChannelEventSink,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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
40; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 40; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 40
; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 40; __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"
, 40); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 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, nsIChannelEventSink>, int32_t( reinterpret_cast
<char*>(static_cast<nsIChannelEventSink*>((StreamLoader
*)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000
))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor
>, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor
*>((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; }
40 nsIInterfaceRequestor)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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
40; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 40; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 40
; __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"
, 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 40; __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"
, 40); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 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, nsIChannelEventSink>, int32_t( reinterpret_cast
<char*>(static_cast<nsIChannelEventSink*>((StreamLoader
*)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000
))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor
>, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor
*>((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; }
41
42/* nsIRequestObserver implementation */
43NS_IMETHODIMPnsresult
44StreamLoader::OnStartRequest(nsIRequest* aRequest) {
45 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"
, 45); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest" ")"
); do { *((volatile int*)__null) = 45; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
46 mRequest = aRequest;
47 mSheetLoadData->NotifyStart(aRequest);
48
49 // It's kinda bad to let Web content send a number that results
50 // in a potentially large allocation directly, but efficiency of
51 // compression bombs is so great that it doesn't make much sense
52 // to require a site to send one before going ahead and allocating.
53 if (nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest)) {
54 int64_t length;
55 nsresult rv = channel->GetContentLength(&length);
56 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && length > 0) {
57 CheckedInt<nsACString::size_type> checkedLength(length);
58 if (!checkedLength.isValid()) {
59 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
60 }
61 if (!mBytes.SetCapacity(checkedLength.value(), fallible)) {
62 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
63 }
64 }
65 NS_GetFinalChannelURI(channel, getter_AddRefs(mFinalChannelURI));
66 nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
67 // we dont return on error here as the error is handled in
68 // SheetLoadData::VerifySheetReadyToParse
69 Unused << secMan->GetChannelResultPrincipal(
70 channel, getter_AddRefs(mChannelResultPrincipal));
71 }
72 if (nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest)) {
73 nsCOMPtr<nsIEventTarget> sts =
74 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1");
75 RefPtr queue =
76 TaskQueue::Create(sts.forget(), "css::StreamLoader Delivery Queue");
77 rr->RetargetDeliveryTo(queue);
78 }
79
80 mSheetLoadData->SetMinimumExpirationTime(
81 nsContentUtils::GetSubresourceCacheExpirationTime(aRequest,
82 mSheetLoadData->mURI));
83
84 // We need to block block resolution of parse promise until we receive
85 // OnStopRequest on Main thread. This is necessary because parse promise
86 // resolution fires OnLoad event OnLoad event must not be dispatched until
87 // OnStopRequest in main thread is processed, for stuff like performance
88 // resource entries.
89 mSheetLoadData->mSheet->BlockParsePromise();
90
91 return NS_OK;
92}
93
94NS_IMETHODIMPnsresult
95StreamLoader::CheckListenerChain() { return NS_OK; }
96
97NS_IMETHODIMPnsresult
98StreamLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
99 MOZ_ASSERT_IF(!StaticPrefs::network_send_OnDataFinished_cssLoader(),do { if (!StaticPrefs::network_send_OnDataFinished_cssLoader(
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(!mOnStopProcessingDone)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mOnStopProcessingDone))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopProcessingDone"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 100); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone"
")"); do { *((volatile int*)__null) = 100; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
100 !mOnStopProcessingDone)do { if (!StaticPrefs::network_send_OnDataFinished_cssLoader(
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(!mOnStopProcessingDone)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mOnStopProcessingDone))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopProcessingDone"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 100); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone"
")"); do { *((volatile int*)__null) = 100; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
101
102 // StreamLoader::OnStopRequest can get triggered twice for a request.
103 // Once from the path
104 // nsIThreadRetargetableStreamListener::OnDataFinished->StreamLoader::OnDataFinished
105 // (non-main thread) and
106 // once from nsIRequestObserver::OnStopRequest path (main thread). It is
107 // guaranteed that we will always get
108 // nsIThreadRetargetableStreamListener::OnDataFinished trigger first and this
109 // is always followed by nsIRequestObserver::OnStopRequest
110
111 // If we are executing OnStopRequest OMT, we need to block resolution of parse
112 // promise and unblock again if we are executing this in main thread.
113 // Resolution of parse promise fires onLoadEvent and this should not happen
114 // before main thread OnStopRequest is dispatched.
115 if (NS_IsMainThread()) {
116 if (mOnDataFinishedTime) {
117 // collect telemetry for the delta between OnDataFinished and
118 // OnStopRequest
119 TimeDuration delta = (TimeStamp::Now() - mOnDataFinishedTime);
120 glean::networking::http_content_cssloader_ondatafinished_to_onstop_delay
121 .AccumulateRawDuration(delta);
122 }
123 mSheetLoadData->mSheet->UnblockParsePromise();
124 }
125
126 if (mOnStopProcessingDone) {
127 return NS_OK;
128 }
129 mOnStopProcessingDone = true;
130
131 nsresult rv = mStatus;
Value stored to 'rv' during its initialization is never read
132 // Decoded data
133 nsCString utf8String;
134 {
135 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
136
137 if (NS_IsMainThread()) {
138 channel->SetNotificationCallbacks(nullptr);
139 }
140
141 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
142 mSheetLoadData->VerifySheetReadyToParse(mStatus, ""_ns, ""_ns, channel,
143 mFinalChannelURI,
144 mChannelResultPrincipal);
145
146 if (!NS_IsMainThread()) {
147 // When processing OMT, we have code paths in VerifySheetReadyToParse
148 // that are main-thread only. We bail on such scenarios and continue
149 // processing them on main thread OnStopRequest.
150 mOnStopProcessingDone = false;
151 }
152 return mStatus;
153 }
154
155 rv = mSheetLoadData->VerifySheetReadyToParse(aStatus, mBOMBytes, mBytes,
156 channel, mFinalChannelURI,
157 mChannelResultPrincipal);
158 if (rv != NS_OK_PARSE_SHEET) {
159 if (!NS_IsMainThread()) {
160 mOnStopProcessingDone = false;
161 }
162 return rv;
163 }
164
165 // At this point all the conditions that requires us to run on main
166 // are checked in VerifySheetReadyToParse
167
168 // BOM detection generally happens during the write callback, but that
169 // won't have happened if fewer than three bytes were received.
170 if (mEncodingFromBOM.isNothing()) {
171 HandleBOM();
172 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"
, 172); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isSome()"
")"); do { *((volatile int*)__null) = 172; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
173 }
174 // Hold the nsStringBuffer for the bytes from the stack to ensure release
175 // after its scope ends
176 nsCString bytes = std::move(mBytes);
177 // The BOM handling has happened, but we still may not have an encoding if
178 // there was no BOM. Ensure we have one.
179 const Encoding* encoding = mEncodingFromBOM.value();
180 if (!encoding) {
181 // No BOM
182 encoding = mSheetLoadData->DetermineNonBOMEncoding(bytes, channel);
183 }
184 mSheetLoadData->mEncoding = encoding;
185
186 size_t validated = 0;
187 if (encoding == UTF_8_ENCODING) {
188 validated = Encoding::UTF8ValidUpTo(bytes);
189 }
190
191 if (validated == bytes.Length()) {
192 // Either this is UTF-8 and all valid, or it's not UTF-8 but is an empty
193 // string. This assumes that an empty string in any encoding decodes to
194 // empty string, which seems like a plausible assumption.
195 utf8String = std::move(bytes);
196 } else {
197 rv = encoding->DecodeWithoutBOMHandling(bytes, utf8String, validated);
198 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"
, 198); return rv; } } while (false)
;
199 }
200 } // run destructor for `bytes`
201
202 // For reasons I don't understand, factoring the below lines into
203 // a method on SheetLoadData resulted in a linker error. Hence,
204 // accessing fields of mSheetLoadData from here.
205 mSheetLoadData->mLoader->ParseSheet(utf8String, mMainThreadSheetLoadData,
206 Loader::AllowAsyncParse::Yes);
207
208 mRequest = nullptr;
209
210 return NS_OK;
211}
212
213/* nsIStreamListener implementation */
214NS_IMETHODIMPnsresult
215StreamLoader::OnDataAvailable(nsIRequest*, nsIInputStream* aInputStream,
216 uint64_t, uint32_t aCount) {
217 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
218 return mStatus;
219 }
220 uint32_t dummy;
221 return aInputStream->ReadSegments(WriteSegmentFun, this, aCount, &dummy);
222}
223
224void StreamLoader::HandleBOM() {
225 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"
, 225); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isNothing()"
")"); do { *((volatile int*)__null) = 225; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
226 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"
, 226); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBytes.IsEmpty()"
")"); do { *((volatile int*)__null) = 226; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
227
228 auto [encoding, bomLength] = Encoding::ForBOM(mBOMBytes);
229 mEncodingFromBOM.emplace(encoding); // Null means no BOM.
230
231 // BOMs are three bytes at most, but may be fewer. Copy over anything
232 // that wasn't part of the BOM to mBytes. Note that we need to track
233 // any BOM bytes as well for SRI handling.
234 mBytes.Append(Substring(mBOMBytes, bomLength));
235 mBOMBytes.Truncate(bomLength);
236}
237
238NS_IMETHODIMPnsresult
239StreamLoader::OnDataFinished(nsresult aResult) {
240 if (StaticPrefs::network_send_OnDataFinished_cssLoader()) {
241 MOZ_ASSERT(mOnDataFinishedTime.IsNull(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnDataFinishedTime.IsNull())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mOnDataFinishedTime.IsNull()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mOnDataFinishedTime.IsNull()" " (" "OnDataFinished should only be called once"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 242); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()"
") (" "OnDataFinished should only be called once" ")"); do {
*((volatile int*)__null) = 242; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
242 "OnDataFinished should only be called once")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnDataFinishedTime.IsNull())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mOnDataFinishedTime.IsNull()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mOnDataFinishedTime.IsNull()" " (" "OnDataFinished should only be called once"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 242); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()"
") (" "OnDataFinished should only be called once" ")"); do {
*((volatile int*)__null) = 242; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
243 mOnDataFinishedTime = TimeStamp::Now();
244 return OnStopRequest(mRequest, aResult);
245 }
246
247 return NS_OK;
248}
249
250NS_IMETHODIMPnsresult
251StreamLoader::GetInterface(const nsIID& aIID, void** aResult) {
252 if (aIID.Equals(NS_GET_IID(nsIChannelEventSink)(nsIChannelEventSink::COMTypeInfo<nsIChannelEventSink, void
>::kIID)
)) {
253 return QueryInterface(aIID, aResult);
254 }
255
256 return NS_NOINTERFACE;
257}
258
259nsresult StreamLoader::AsyncOnChannelRedirect(
260 nsIChannel* aOld, nsIChannel* aNew, uint32_t aFlags,
261 nsIAsyncVerifyRedirectCallback* aCallback) {
262 mSheetLoadData->SetMinimumExpirationTime(
263 nsContentUtils::GetSubresourceCacheExpirationTime(aOld,
264 mSheetLoadData->mURI));
265
266 aCallback->OnRedirectVerifyCallback(NS_OK);
267
268 return NS_OK;
269}
270
271nsresult StreamLoader::WriteSegmentFun(nsIInputStream*, void* aClosure,
272 const char* aSegment, uint32_t,
273 uint32_t aCount, uint32_t* aWriteCount) {
274 *aWriteCount = 0;
275 StreamLoader* self = static_cast<StreamLoader*>(aClosure);
276 if (NS_FAILED(self->mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(self->mStatus))
, 0)))
) {
277 return self->mStatus;
278 }
279
280 // If we haven't done BOM detection yet, divert bytes into the special buffer.
281 if (self->mEncodingFromBOM.isNothing()) {
282 size_t bytesToCopy = std::min<size_t>(3 - self->mBOMBytes.Length(), aCount);
283 self->mBOMBytes.Append(aSegment, bytesToCopy);
284 aSegment += bytesToCopy;
285 *aWriteCount += bytesToCopy;
286 aCount -= bytesToCopy;
287
288 if (self->mBOMBytes.Length() == 3) {
289 self->HandleBOM();
290 } else {
291 return NS_OK;
292 }
293 }
294
295 if (!self->mBytes.Append(aSegment, aCount, fallible)) {
296 self->mBytes.Truncate();
297 return (self->mStatus = NS_ERROR_OUT_OF_MEMORY);
298 }
299
300 *aWriteCount += aCount;
301 return NS_OK;
302}
303
304} // namespace mozilla::css