Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/extensions/spellcheck/src/./../../../../extensions/spellcheck/src/mozEnglishWordUtils.cpp
Warning:line 40, column 19
Value stored to 'startWord' 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_spellcheck_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/extensions/spellcheck/src -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/extensions/spellcheck/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/extensions/spellcheck/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/extensions/spellcheck/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/extensions/spellcheck/ipc -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_spellcheck_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 "mozEnglishWordUtils.h"
6#include "nsComponentManagerUtils.h"
7#include "nsReadableUtils.h"
8#include "nsUnicharUtils.h"
9#include "nsUnicodeProperties.h"
10#include "nsCRT.h"
11
12NS_IMPL_CYCLE_COLLECTION(mozEnglishWordUtils, mURLDetector)mozEnglishWordUtils::cycleCollection mozEnglishWordUtils::_cycleCollectorGlobal
; void mozEnglishWordUtils::cycleCollection::Unlink(void* p) {
mozEnglishWordUtils* tmp = DowncastCCParticipant<mozEnglishWordUtils
>(p); ImplCycleCollectionUnlink(tmp->mURLDetector); (void
)tmp; } nsresult mozEnglishWordUtils::cycleCollection::TraverseNative
( void* p, nsCycleCollectionTraversalCallback& cb) { mozEnglishWordUtils
* tmp = DowncastCCParticipant<mozEnglishWordUtils>(p); cb
.DescribeRefCountedNode(tmp->mRefCnt.get(), "mozEnglishWordUtils"
); ImplCycleCollectionTraverse(cb, tmp->mURLDetector, "mURLDetector"
, 0); (void)tmp; return NS_OK; }
13
14mozEnglishWordUtils::mozEnglishWordUtils() {
15 mURLDetector = do_CreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID"@mozilla.org/txttohtmlconv;1");
16}
17
18mozEnglishWordUtils::~mozEnglishWordUtils() = default;
19
20// This needs vast improvement
21
22// static
23bool mozEnglishWordUtils::ucIsAlpha(char16_t aChar) {
24 // XXX we have to fix callers to handle the full Unicode range
25 return nsUGenCategory::kLetter == mozilla::unicode::GetGenCategory(aChar);
26}
27
28bool mozEnglishWordUtils::FindNextWord(const nsAString& aWord, uint32_t offset,
29 int32_t* begin, int32_t* end) {
30 if (offset >= aWord.Length()) {
31 *begin = -1;
32 *end = -1;
33 return false;
34 }
35
36 const char16_t* word = aWord.BeginReading();
37 uint32_t length = aWord.Length();
38 const char16_t* p = word + offset;
39 const char16_t* endbuf = word + length;
40 const char16_t* startWord = p;
Value stored to 'startWord' during its initialization is never read
41
42 // XXX These loops should be modified to handle non-BMP characters.
43 // if previous character is a word character, need to advance out of the
44 // word
45 if (offset > 0 && ucIsAlpha(*(p - 1))) {
46 while (p < endbuf && ucIsAlpha(*p)) {
47 p++;
48 }
49 }
50 while ((p < endbuf) && (!ucIsAlpha(*p))) {
51 p++;
52 }
53 startWord = p;
54 while ((p < endbuf) && ((ucIsAlpha(*p)) || (*p == '\''))) {
55 p++;
56 }
57
58 // we could be trying to break down a url, we don't want to break a url into
59 // parts, instead we want to find out if it really is a url and if so, skip
60 // it, advancing startWord to a point after the url.
61
62 // before we spend more time looking to see if the word is a url, look for a
63 // url identifer and make sure that identifer isn't the last character in
64 // the word fragment.
65 if ((p < endbuf - 1) && (*p == ':' || *p == '@' || *p == '.')) {
66 // ok, we have a possible url...do more research to find out if we really
67 // have one and determine the length of the url so we can skip over it.
68
69 if (mURLDetector) {
70 int32_t startPos = -1;
71 int32_t endPos = -1;
72
73 mURLDetector->FindURLInPlaintext(startWord, endbuf - startWord,
74 p - startWord, &startPos, &endPos);
75
76 // ok, if we got a url, adjust the array bounds, skip the current url
77 // text and find the next word again
78 if (startPos != -1 && endPos != -1) {
79 startWord = p + endPos + 1; // skip over the url
80
81 // now recursively call FindNextWord to search for the next word now
82 // that we have skipped the url
83 return FindNextWord(aWord, startWord - word, begin, end);
84 }
85 }
86 }
87
88 while ((p > startWord) && (*(p - 1) == '\'')) { // trim trailing apostrophes
89 p--;
90 }
91
92 if (startWord == endbuf) {
93 *begin = -1;
94 *end = -1;
95 return false;
96 }
97 *begin = startWord - word;
98 *end = p - word;
99 return true;
100}