Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/extensions/spellcheck/src/mozEnglishWordUtils.cpp
Warning:line 42, 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 -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=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/extensions/spellcheck/src -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/extensions/spellcheck/src -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 MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/extensions/spellcheck/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/extensions/spellcheck/src -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/extensions/spellcheck/ipc -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-18/lib/clang/18/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 -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-07-27-022226-2793976-1 -x c++ Unified_cpp_spellcheck_src0.cpp
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6#include "mozEnglishWordUtils.h"
7#include "nsComponentManagerUtils.h"
8#include "nsReadableUtils.h"
9#include "nsUnicharUtils.h"
10#include "nsUnicodeProperties.h"
11#include "nsCRT.h"
12#include "mozilla/Likely.h"
13
14NS_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; }
15
16mozEnglishWordUtils::mozEnglishWordUtils() {
17 mURLDetector = do_CreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID"@mozilla.org/txttohtmlconv;1");
18}
19
20mozEnglishWordUtils::~mozEnglishWordUtils() {}
21
22// This needs vast improvement
23
24// static
25bool mozEnglishWordUtils::ucIsAlpha(char16_t aChar) {
26 // XXX we have to fix callers to handle the full Unicode range
27 return nsUGenCategory::kLetter == mozilla::unicode::GetGenCategory(aChar);
28}
29
30bool mozEnglishWordUtils::FindNextWord(const nsAString& aWord, uint32_t offset,
31 int32_t* begin, int32_t* end) {
32 if (offset >= aWord.Length()) {
33 *begin = -1;
34 *end = -1;
35 return false;
36 }
37
38 const char16_t* word = aWord.BeginReading();
39 uint32_t length = aWord.Length();
40 const char16_t* p = word + offset;
41 const char16_t* endbuf = word + length;
42 const char16_t* startWord = p;
Value stored to 'startWord' during its initialization is never read
43
44 // XXX These loops should be modified to handle non-BMP characters.
45 // if previous character is a word character, need to advance out of the
46 // word
47 if (offset > 0 && ucIsAlpha(*(p - 1))) {
48 while (p < endbuf && ucIsAlpha(*p)) {
49 p++;
50 }
51 }
52 while ((p < endbuf) && (!ucIsAlpha(*p))) {
53 p++;
54 }
55 startWord = p;
56 while ((p < endbuf) && ((ucIsAlpha(*p)) || (*p == '\''))) {
57 p++;
58 }
59
60 // we could be trying to break down a url, we don't want to break a url into
61 // parts, instead we want to find out if it really is a url and if so, skip
62 // it, advancing startWord to a point after the url.
63
64 // before we spend more time looking to see if the word is a url, look for a
65 // url identifer and make sure that identifer isn't the last character in
66 // the word fragment.
67 if ((p < endbuf - 1) && (*p == ':' || *p == '@' || *p == '.')) {
68 // ok, we have a possible url...do more research to find out if we really
69 // have one and determine the length of the url so we can skip over it.
70
71 if (mURLDetector) {
72 int32_t startPos = -1;
73 int32_t endPos = -1;
74
75 mURLDetector->FindURLInPlaintext(startWord, endbuf - startWord,
76 p - startWord, &startPos, &endPos);
77
78 // ok, if we got a url, adjust the array bounds, skip the current url
79 // text and find the next word again
80 if (startPos != -1 && endPos != -1) {
81 startWord = p + endPos + 1; // skip over the url
82
83 // now recursively call FindNextWord to search for the next word now
84 // that we have skipped the url
85 return FindNextWord(aWord, startWord - word, begin, end);
86 }
87 }
88 }
89
90 while ((p > startWord) && (*(p - 1) == '\'')) { // trim trailing apostrophes
91 p--;
92 }
93
94 if (startWord == endbuf) {
95 *begin = -1;
96 *end = -1;
97 return false;
98 }
99 *begin = startWord - word;
100 *end = p - word;
101 return true;
102}