Bug Summary

File:root/firefox-clang/intl/icu/source/i18n/number_usageprefs.cpp
Warning:line 119, column 13
Value stored to 'status' 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 number_usageprefs.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/i18n -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -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_I18N_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/i18n -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -I /root/firefox-clang/intl/icu/source/common -I /root/firefox-clang/mfbt/double-conversion -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/i18n/number_usageprefs.cpp
1// © 2020 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3
4#include "unicode/utypes.h"
5
6#if !UCONFIG_NO_FORMATTING0
7
8#include "number_usageprefs.h"
9#include "cstring.h"
10#include "number_decimalquantity.h"
11#include "number_microprops.h"
12#include "number_roundingutils.h"
13#include "number_skeletons.h"
14#include "unicode/char16ptr.h"
15#include "unicode/currunit.h"
16#include "unicode/fmtable.h"
17#include "unicode/measure.h"
18#include "unicode/numberformatter.h"
19#include "unicode/platform.h"
20#include "unicode/unum.h"
21#include "unicode/urename.h"
22#include "units_data.h"
23
24using namespace icu;
25using namespace icu::number;
26using namespace icu::number::impl;
27using icu::StringSegment;
28using icu::units::ConversionRates;
29
30// Copy constructor
31StringProp::StringProp(const StringProp &other) : StringProp() {
32 this->operator=(other);
33}
34
35// Copy assignment operator
36StringProp &StringProp::operator=(const StringProp &other) {
37 if (this == &other) { return *this; } // self-assignment: no-op
38 fLength = 0;
39 fError = other.fError;
40 if (fValue != nullptr) {
41 uprv_freeuprv_free_77(fValue);
42 fValue = nullptr;
43 }
44 if (other.fValue == nullptr) {
45 return *this;
46 }
47 if (U_FAILURE(other.fError)) {
48 // We don't bother trying to allocating memory if we're in any case busy
49 // copying an errored StringProp.
50 return *this;
51 }
52 fValue = static_cast<char*>(uprv_mallocuprv_malloc_77(other.fLength + 1));
53 if (fValue == nullptr) {
54 fError = U_MEMORY_ALLOCATION_ERROR;
55 return *this;
56 }
57 fLength = other.fLength;
58 uprv_strncpy(fValue, other.fValue, fLength + 1):: strncpy(fValue, other.fValue, fLength + 1);
59 return *this;
60}
61
62// Move constructor
63StringProp::StringProp(StringProp &&src) noexcept : fValue(src.fValue),
64 fLength(src.fLength),
65 fError(src.fError) {
66 // Take ownership away from src if necessary
67 src.fValue = nullptr;
68}
69
70// Move assignment operator
71StringProp &StringProp::operator=(StringProp &&src) noexcept {
72 if (this == &src) {
73 return *this;
74 }
75 if (fValue != nullptr) {
76 uprv_freeuprv_free_77(fValue);
77 }
78 fValue = src.fValue;
79 fLength = src.fLength;
80 fError = src.fError;
81 // Take ownership away from src if necessary
82 src.fValue = nullptr;
83 return *this;
84}
85
86StringProp::~StringProp() {
87 if (fValue != nullptr) {
88 uprv_freeuprv_free_77(fValue);
89 fValue = nullptr;
90 }
91}
92
93void StringProp::set(StringPiece value) {
94 if (fValue != nullptr) {
95 uprv_freeuprv_free_77(fValue);
96 fValue = nullptr;
97 }
98 fLength = value.length();
99 fValue = static_cast<char*>(uprv_mallocuprv_malloc_77(fLength + 1));
100 if (fValue == nullptr) {
101 fLength = 0;
102 fError = U_MEMORY_ALLOCATION_ERROR;
103 return;
104 }
105 if (fLength > 0) {
106 uprv_strncpy(fValue, value.data(), fLength):: strncpy(fValue, value.data(), fLength);
107 }
108 fValue[fLength] = 0;
109}
110
111// Populates micros.mixedMeasures and modifies quantity, based on the values in
112// measures.
113void mixedMeasuresToMicrosmixedMeasuresToMicros_77(const MaybeStackVector<Measure> &measures, DecimalQuantity *quantity,
114 MicroProps *micros, UErrorCode status) {
115 micros->mixedMeasuresCount = measures.length();
116
117 if (micros->mixedMeasures.getCapacity() < micros->mixedMeasuresCount) {
118 if (micros->mixedMeasures.resize(micros->mixedMeasuresCount) == nullptr) {
119 status = U_MEMORY_ALLOCATION_ERROR;
Value stored to 'status' is never read
120 return;
121 }
122 }
123
124 for (int32_t i = 0; i < micros->mixedMeasuresCount; i++) {
125 switch (measures[i]->getNumber().getType()) {
126 case Formattable::kInt64:
127 micros->mixedMeasures[i] = measures[i]->getNumber().getInt64();
128 break;
129
130 case Formattable::kDouble:
131 U_ASSERT(micros->indexOfQuantity < 0)(static_cast <bool> (micros->indexOfQuantity < 0)
? void (0) : __assert_fail ("micros->indexOfQuantity < 0"
, __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__
))
;
132 quantity->setToDouble(measures[i]->getNumber().getDouble());
133 micros->indexOfQuantity = i;
134 break;
135
136 default:
137 U_ASSERT(0 == "Found a Measure Number which is neither a double nor an int")(static_cast <bool> (0 == "Found a Measure Number which is neither a double nor an int"
) ? void (0) : __assert_fail ("0 == \"Found a Measure Number which is neither a double nor an int\""
, __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__
))
;
138 UPRV_UNREACHABLE_EXITabort();
139 break;
140 }
141
142 if (U_FAILURE(status)) {
143 return;
144 }
145 }
146
147 if (micros->indexOfQuantity < 0) {
148 // There is no quantity.
149 status = U_INTERNAL_PROGRAM_ERROR;
150 }
151}
152
153UsagePrefsHandler::UsagePrefsHandler(const Locale &locale,
154 const MeasureUnit &inputUnit,
155 const StringPiece usage,
156 const MicroPropsGenerator *parent,
157 UErrorCode &status)
158 : fUnitsRouter(inputUnit, locale, usage, status),
159 fParent(parent) {
160}
161
162void UsagePrefsHandler::processQuantity(DecimalQuantity &quantity, MicroProps &micros,
163 UErrorCode &status) const {
164 fParent->processQuantity(quantity, micros, status);
165 if (U_FAILURE(status)) {
166 return;
167 }
168
169 quantity.roundToInfinity(); // Enables toDouble
170 const units::RouteResult routed = fUnitsRouter.route(quantity.toDouble(), &micros.rounder, status);
171 if (U_FAILURE(status)) {
172 return;
173 }
174 const MaybeStackVector<Measure>& routedMeasures = routed.measures;
175 micros.outputUnit = routed.outputUnit.copy(status).build(status);
176 if (U_FAILURE(status)) {
177 return;
178 }
179
180 mixedMeasuresToMicrosmixedMeasuresToMicros_77(routedMeasures, &quantity, &micros, status);
181}
182
183UnitConversionHandler::UnitConversionHandler(const MeasureUnit &targetUnit,
184 const MicroPropsGenerator *parent, UErrorCode &status)
185 : fOutputUnit(targetUnit), fParent(parent) {
186 MeasureUnitImpl tempInput, tempOutput;
187
188 ConversionRates conversionRates(status);
189 if (U_FAILURE(status)) {
190 return;
191 }
192
193 const MeasureUnitImpl &targetUnitImpl =
194 MeasureUnitImpl::forMeasureUnit(targetUnit, tempOutput, status);
195 fUnitConverter.adoptInsteadAndCheckErrorCode(
196 new ComplexUnitsConverter(targetUnitImpl, conversionRates, status), status);
197}
198
199void UnitConversionHandler::processQuantity(DecimalQuantity &quantity, MicroProps &micros,
200 UErrorCode &status) const {
201 fParent->processQuantity(quantity, micros, status);
202 if (U_FAILURE(status)) {
203 return;
204 }
205 quantity.roundToInfinity(); // Enables toDouble
206 MaybeStackVector<Measure> measures =
207 fUnitConverter->convert(quantity.toDouble(), &micros.rounder, status);
208 micros.outputUnit = fOutputUnit;
209 if (U_FAILURE(status)) {
210 return;
211 }
212
213 mixedMeasuresToMicrosmixedMeasuresToMicros_77(measures, &quantity, &micros, status);
214}
215
216#endif /* #if !UCONFIG_NO_FORMATTING */