Bug Summary

File:root/firefox-clang/intl/icu/source/common/usetiter.cpp
Warning:line 147, column 5
Returning null reference

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 usetiter.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/config/external/icu/common -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/common -resource-dir /usr/lib/llvm-21/lib/clang/21 -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/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D _GLIBCXX_ASSERTIONS -D DEBUG=1 -D U_COMMON_IMPLEMENTATION -D _LIBCPP_DISABLE_DEPRECATION_WARNINGS -D U_USING_ICU_NAMESPACE=0 -D U_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -D U_HIDE_OBSOLETE_UTF_OLD_H=1 -D UCONFIG_NO_LEGACY_CONVERSION -D UCONFIG_NO_TRANSLITERATION -D UCONFIG_NO_REGULAR_EXPRESSIONS -D UCONFIG_NO_BREAK_ITERATION -D UCONFIG_NO_IDNA -D UCONFIG_NO_MF2 -D U_CHARSET_IS_UTF8 -D UNISTR_FROM_CHAR_EXPLICIT=explicit -D UNISTR_FROM_STRING_EXPLICIT=explicit -D U_ENABLE_DYLOAD=0 -D U_DEBUG=1 -I /root/firefox-clang/config/external/icu/common -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/common -I /root/firefox-clang/intl/icu/source/i18n -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/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-21/lib/clang/21/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=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-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 -Wno-comma -Wno-implicit-const-int-float-conversion -Wno-macro-redefined -Wno-microsoft-include -Wno-tautological-unsigned-enum-zero-compare -Wno-unreachable-code-loop-increment -Wno-unreachable-code-return -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -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-2025-06-27-100320-3286336-1 -x c++ /root/firefox-clang/intl/icu/source/common/usetiter.cpp
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4**********************************************************************
5* Copyright (c) 2002-2006, International Business Machines
6* Corporation and others. All Rights Reserved.
7**********************************************************************
8*/
9#include "unicode/usetiter.h"
10#include "unicode/uniset.h"
11#include "unicode/unistr.h"
12#include "uvector.h"
13
14U_NAMESPACE_BEGINnamespace icu_77 {
15
16UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UnicodeSetIterator)UClassID UnicodeSetIterator::getStaticClassID() { static char
classID = 0; return (UClassID)&classID; } UClassID UnicodeSetIterator
::getDynamicClassID() const { return UnicodeSetIterator::getStaticClassID
(); }
17
18/**
19 * Create an iterator
20 * @param set set to iterate over
21 */
22UnicodeSetIterator::UnicodeSetIterator(const UnicodeSet& uSet) {
23 cpString = nullptr;
24 reset(uSet);
25}
26
27/**
28 * Create an iterator. Convenience for when the contents are to be set later.
29 */
30UnicodeSetIterator::UnicodeSetIterator() {
31 this->set = nullptr;
32 cpString = nullptr;
33 reset();
34}
35
36UnicodeSetIterator::~UnicodeSetIterator() {
37 delete cpString;
38}
39
40/**
41 * Returns the next element in the set.
42 * @return true if there was another element in the set.
43 * if so, if codepoint == IS_STRING, the value is a string in the string field
44 * else the value is a single code point in the codepoint field.
45 * <br>You are guaranteed that the codepoints are in sorted order, and the strings are in sorted order,
46 * and that all code points are returned before any strings are returned.
47 * <br>Note also that the codepointEnd is undefined after calling this method.
48 */
49UBool UnicodeSetIterator::next() {
50 if (nextElement <= endElement) {
51 codepoint = codepointEnd = nextElement++;
52 string = nullptr;
53 return true;
54 }
55 if (range < endRange) {
56 loadRange(++range);
57 codepoint = codepointEnd = nextElement++;
58 string = nullptr;
59 return true;
60 }
61
62 if (nextString >= stringCount) return false;
63 codepoint = static_cast<UChar32>(IS_STRING); // signal that value is actually a string
64 string = static_cast<const UnicodeString*>(set->strings_->elementAt(nextString++));
65 return true;
66}
67
68/**
69 * @return true if there was another element in the set.
70 * if so, if codepoint == IS_STRING, the value is a string in the string field
71 * else the value is a range of codepoints in the <codepoint, codepointEnd> fields.
72 * <br>Note that the codepoints are in sorted order, and the strings are in sorted order,
73 * and that all code points are returned before any strings are returned.
74 * <br>You are guaranteed that the ranges are in sorted order, and the strings are in sorted order,
75 * and that all ranges are returned before any strings are returned.
76 * <br>You are also guaranteed that ranges are disjoint and non-contiguous.
77 * <br>Note also that the codepointEnd is undefined after calling this method.
78 */
79UBool UnicodeSetIterator::nextRange() {
80 string = nullptr;
81 if (nextElement <= endElement) {
82 codepointEnd = endElement;
83 codepoint = nextElement;
84 nextElement = endElement+1;
85 return true;
86 }
87 if (range < endRange) {
88 loadRange(++range);
89 codepointEnd = endElement;
90 codepoint = nextElement;
91 nextElement = endElement+1;
92 return true;
93 }
94
95 if (nextString >= stringCount) return false;
96 codepoint = static_cast<UChar32>(IS_STRING); // signal that value is actually a string
97 string = static_cast<const UnicodeString*>(set->strings_->elementAt(nextString++));
98 return true;
99}
100
101/**
102 *@param set the set to iterate over. This allows reuse of the iterator.
103 */
104void UnicodeSetIterator::reset(const UnicodeSet& uSet) {
105 this->set = &uSet;
106 reset();
107}
108
109/**
110 * Resets to the start, to allow the iteration to start over again.
111 */
112void UnicodeSetIterator::reset() {
113 if (set == nullptr) {
114 // Set up indices to empty iteration
115 endRange = -1;
116 stringCount = 0;
117 } else {
118 endRange = set->getRangeCount() - 1;
119 stringCount = set->stringsSize();
120 }
121 range = 0;
122 endElement = -1;
123 nextElement = 0;
124 if (endRange >= 0) {
125 loadRange(range);
126 }
127 nextString = 0;
128 string = nullptr;
129}
130
131void UnicodeSetIterator::loadRange(int32_t iRange) {
132 nextElement = set->getRangeStart(iRange);
133 endElement = set->getRangeEnd(iRange);
134}
135
136
137const UnicodeString& UnicodeSetIterator::getString() {
138 if (string == nullptr && codepoint != static_cast<UChar32>(IS_STRING)) {
1
Assuming pointer value is null
2
Assuming field 'codepoint' is equal to IS_STRING
3
Taking false branch
139 if (cpString == nullptr) {
140 cpString = new UnicodeString();
141 }
142 if (cpString != nullptr) {
143 cpString->setTo(codepoint);
144 }
145 string = cpString;
146 }
147 return *string;
4
Returning null reference
148}
149
150U_NAMESPACE_END}
151
152//eof