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 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | |
19 | namespace mozilla::css { |
20 | |
21 | StreamLoader::StreamLoader(SheetLoadData& aSheetLoadData) |
22 | : mSheetLoadData(&aSheetLoadData), mStatus(NS_OK) {} |
23 | |
24 | StreamLoader::~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 | |
30 | NS_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 */ |
34 | NS_IMETHODIMPnsresult |
35 | StreamLoader::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 | |
79 | NS_IMETHODIMPnsresult |
80 | StreamLoader::CheckListenerChain() { return NS_OK; } |
81 | |
82 | NS_IMETHODIMPnsresult |
83 | StreamLoader::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 */ |
152 | NS_IMETHODIMPnsresult |
153 | StreamLoader::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 | |
162 | NS_IMETHODIMPnsresult |
163 | StreamLoader::OnDataFinished(nsresult aStatus) { return NS_OK; } |
164 | |
165 | void 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 | |
179 | nsresult 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 |