Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/src/./../../../../js/xpconnect/src/XPCJSWeakReference.cpp
Warning:line 40, 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 -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_js_xpconnect_src0.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=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/src -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/src -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 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -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 MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/js/xpconnect/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/toolkit/components/telemetry -I /root/firefox-clang/xpcom/base -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/xpcom/components -I /root/firefox-clang/js/xpconnect/loader -I /root/firefox-clang/js/xpconnect/wrappers -I /root/firefox-clang/caps -I /root/firefox-clang/dom/base -I /root/firefox-clang/dom/bindings -I /root/firefox-clang/dom/html -I /root/firefox-clang/layout/base -I /root/firefox-clang/layout/style -I /root/firefox-clang/netwerk/base -I /root/firefox-clang/xpcom/components -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 -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++ Unified_cpp_js_xpconnect_src0.cpp
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include "XPCJSWeakReference.h"
6
7#include "nsContentUtils.h"
8#include "xpcprivate.h"
9
10using namespace JS;
11
12xpcJSWeakReference::xpcJSWeakReference() = default;
13
14NS_IMPL_ISUPPORTS(xpcJSWeakReference, xpcIJSWeakReference)MozExternalRefCountType xpcJSWeakReference::AddRef(void) { static_assert
(!std::is_destructible_v<xpcJSWeakReference>, "Reference-counted class "
"xpcJSWeakReference" " 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" ")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp"
, 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 14
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("xpcJSWeakReference" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("xpcJSWeakReference" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"xpcJSWeakReference\" != nullptr" " (" "Must specify a name"
")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp"
, 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"xpcJSWeakReference\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 14); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("xpcJSWeakReference" " not thread-safe"); nsrefcnt count = ++
mRefCnt; NS_LogAddRef((this), (count), ("xpcJSWeakReference")
, (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
xpcJSWeakReference::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"
")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp"
, 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 14)
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("xpcJSWeakReference" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("xpcJSWeakReference" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"xpcJSWeakReference\" != nullptr" " (" "Must specify a name"
")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp"
, 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"xpcJSWeakReference\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 14); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("xpcJSWeakReference" " not thread-safe"); const char* const nametmp
= "xpcJSWeakReference"; nsrefcnt count = --mRefCnt; NS_LogRelease
((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete
(this); return 0; } return count; } nsresult xpcJSWeakReference
::QueryInterface(const nsIID& aIID, void** aInstancePtr) {
do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "QueryInterface requires a non-NULL destination!", "aInstancePtr"
, "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp", 14
); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<xpcJSWeakReference, xpcIJSWeakReference>
, int32_t( reinterpret_cast<char*>(static_cast<xpcIJSWeakReference
*>((xpcJSWeakReference*)0x1000)) - reinterpret_cast<char
*>((xpcJSWeakReference*)0x1000))}, {&mozilla::detail::
kImplementedIID<xpcJSWeakReference, nsISupports>, int32_t
(reinterpret_cast<char*>(static_cast<nsISupports*>
( static_cast<xpcIJSWeakReference*>((xpcJSWeakReference
*)0x1000))) - reinterpret_cast<char*>((xpcJSWeakReference
*)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table
) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI
(static_cast<void*>(this), aIID, aInstancePtr, table); return
rv; }
15
16nsresult xpcJSWeakReference::Init(JSContext* cx, const JS::Value& object) {
17 if (!object.isObject()) {
18 return NS_OK;
19 }
20
21 JS::RootedObject obj(cx, &object.toObject());
22
23 XPCCallContext ccx(cx);
24
25 // See if the object is a wrapped native that supports weak references.
26 nsCOMPtr<nsISupports> supports = xpc::ReflectorToISupportsDynamic(obj, cx);
27 nsCOMPtr<nsISupportsWeakReference> supportsWeakRef =
28 do_QueryInterface(supports);
29 if (supportsWeakRef) {
30 supportsWeakRef->GetWeakReference(getter_AddRefs(mReferent));
31 if (mReferent) {
32 return NS_OK;
33 }
34 }
35 // If it's not a wrapped native, or it is a wrapped native that does not
36 // support weak references, fall back to getting a weak ref to the object.
37
38 // See if object is a wrapped JSObject.
39 RefPtr<nsXPCWrappedJS> wrapped;
40 nsresult rv = nsXPCWrappedJS::GetNewOrUsed(cx, obj, NS_GET_IID(nsISupports)(nsISupports::kIID),
Value stored to 'rv' during its initialization is never read
41 getter_AddRefs(wrapped));
42 if (!wrapped) {
43 NS_ERROR("can't get nsISupportsWeakReference wrapper for obj")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "can't get nsISupportsWeakReference wrapper for obj"
, "Error", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp"
, 43); MOZ_PretendNoReturn(); } while (0)
;
44 return rv;
45 }
46
47 return wrapped->GetWeakReference(getter_AddRefs(mReferent));
48}
49
50NS_IMETHODIMPnsresult
51xpcJSWeakReference::Get(JSContext* aCx, MutableHandleValue aRetval) {
52 aRetval.setNull();
53
54 if (!mReferent) {
55 return NS_OK;
56 }
57
58 nsCOMPtr<nsISupports> supports = do_QueryReferent(mReferent);
59 if (!supports) {
60 return NS_OK;
61 }
62
63 nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(supports);
64 if (!wrappedObj) {
65 // We have a generic XPCOM object that supports weak references here.
66 // Wrap it and pass it out.
67 return nsContentUtils::WrapNative(aCx, supports, &NS_GET_IID(nsISupports)(nsISupports::kIID),
68 aRetval);
69 }
70
71 JS::RootedObject obj(aCx, wrappedObj->GetJSObject());
72 if (!obj) {
73 return NS_OK;
74 }
75
76 // Most users of XPCWrappedJS don't need to worry about
77 // re-wrapping because things are implicitly rewrapped by
78 // xpcconvert. However, because we're doing this directly
79 // through the native call context, we need to call
80 // JS_WrapObject().
81 if (!JS_WrapObject(aCx, &obj)) {
82 return NS_ERROR_FAILURE;
83 }
84
85 aRetval.setObject(*obj);
86 return NS_OK;
87}