Bug Summary

File:IccProfLib/IccEval.cpp
Warning:line 207, column 10
Potential leak of memory pointed to by 'steps'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name IccEval.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=osx -analyzer-checker=security.insecureAPI.decodeValueOfObjCType -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 -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=14.0 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 1015.7 -fprofile-instrument=clang -fcoverage-mapping -fcoverage-compilation-dir=/Users/xss/DemoIccMAX-hoyt-master/build/IccProfLib -resource-dir /usr/local/Cellar/llvm/17.0.3/lib/clang/17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -D IccProfLib2_EXPORTS -I /Users/xss/DemoIccMAX-hoyt-master/build/Cmake/../../IccProfLib -I /Developer/Headers/FlatCarbon -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks -internal-isystem /usr/local/Cellar/llvm/17.0.3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/include -internal-isystem /usr/local/Cellar/llvm/17.0.3/lib/clang/17/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/Users/xss/DemoIccMAX-hoyt-master/build/IccProfLib -ferror-limit 19 -fsanitize=address -fsanitize-system-ignorelist=/usr/local/Cellar/llvm/17.0.3/lib/clang/17/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -analyzer-output=html -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/l9/sd9kj1px4yq2wc5_lkwhlt6w0000gn/T/scan-build-2023-10-28-102616-57860-1 -x c++ /Users/xss/DemoIccMAX-hoyt-master/IccProfLib/IccEval.cpp
1/** @file
2File: IccEval.cpp
3
4Contains: Implementation of the CIccProfile Evaluation utilites.
5
6Version: V1
7
8Copyright: (c) see ICC Software License
9*/
10
11/*
12* The ICC Software License, Version 0.2
13*
14*
15* Copyright (c) 2003-2012 The International Color Consortium. All rights
16* reserved.
17*
18* Redistribution and use in source and binary forms, with or without
19* modification, are permitted provided that the following conditions
20* are met:
21*
22* 1. Redistributions of source code must retain the above copyright
23* notice, this list of conditions and the following disclaimer.
24*
25* 2. Redistributions in binary form must reproduce the above copyright
26* notice, this list of conditions and the following disclaimer in
27* the documentation and/or other materials provided with the
28* distribution.
29*
30* 3. In the absence of prior written permission, the names "ICC" and "The
31* International Color Consortium" must not be used to imply that the
32* ICC organization endorses or promotes products derived from this
33* software.
34*
35*
36* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39* DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
40* ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47* SUCH DAMAGE.
48* ====================================================================
49*
50* This software consists of voluntary contributions made by many
51* individuals on behalf of the The International Color Consortium.
52*
53*
54* Membership in the ICC is encouraged when this software is used for
55* commercial purposes.
56*
57*
58* For more information on The International Color Consortium, please
59* see <http://www.color.org/>.
60*
61*
62*/
63
64//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -Initial implementation by Max Derhak 5-15-2003
68//
69//////////////////////////////////////////////////////////////////////
70
71#include <math.h>
72#include "IccEval.h"
73#include "IccTag.h"
74#include <iostream>
75#include <typeinfo>
76#include <cassert>
77
78#ifdef USEREFICCMAXNAMESPACE
79namespace refIccMAX {
80#endif
81
82static const icFloatNumber SMALLNUM = (icFloatNumber)0.0001;
83static const icFloatNumber LESSTHANONE = (icFloatNumber)(1.0 - SMALLNUM);
84
85icStatusCMM CIccEvalCompare::EvaluateProfile(CIccProfile *pProfile, icUInt8Number nGran/* =0 */,
86 icRenderingIntent nIntent/* =icUnknownIntent */, icXformInterp nInterp/* =icInterpLinear */,
87 bool buseMpeTags/* =true */)
88{
89 if (!pProfile
3.1
'pProfile' is non-null
)
90 {
91 return icCmmStatCantOpenProfile;
92 }
93
94 if (pProfile->m_Header.deviceClass!=icSigInputClass &&
4
Assuming field 'deviceClass' is equal to icSigInputClass
95 pProfile->m_Header.deviceClass!=icSigDisplayClass &&
96 pProfile->m_Header.deviceClass!=icSigOutputClass &&
97 pProfile->m_Header.deviceClass!=icSigColorSpaceClass)
98 {
99 return icCmmStatInvalidProfile;
100 }
101
102 CIccCmm dev2Lab(icSigUnknownData((icColorSpaceSignature) 0x3f3f3f3f), icSigLabData);
103 CIccCmm Lab2Dev2Lab(icSigLabData, icSigLabData, false);
104
105 icStatusCMM result;
106
107 result = dev2Lab.AddXform(*pProfile, nIntent, nInterp, NULL__null, icXformLutColorimetric, buseMpeTags);
108
109 if (result!=icCmmStatOk) {
5
Assuming 'result' is equal to icCmmStatOk
6
Taking false branch
110 return result;
111 }
112
113 result = dev2Lab.Begin();
114 if (result != icCmmStatOk) {
7
Assuming 'result' is equal to icCmmStatOk
8
Taking false branch
115 return result;
116 }
117
118 result = Lab2Dev2Lab.AddXform(*pProfile, nIntent, nInterp, NULL__null, icXformLutColorimetric, buseMpeTags);
119 if (result != icCmmStatOk) {
9
Assuming 'result' is equal to icCmmStatOk
10
Taking false branch
120 return result;
121 }
122
123 result = Lab2Dev2Lab.AddXform(*pProfile, nIntent, nInterp, NULL__null, icXformLutColorimetric, buseMpeTags);
124 if (result != icCmmStatOk) {
11
Assuming 'result' is equal to icCmmStatOk
12
Taking false branch
125 return result;
126 }
127
128 result = Lab2Dev2Lab.Begin();
129 if (result != icCmmStatOk) {
13
Assuming 'result' is equal to icCmmStatOk
14
Taking false branch
130 return result;
131 }
132
133 icFloatNumber sPixel[15];
134 icFloatNumber devPcs[15], roundPcs1[15], roundPcs2[15];
135
136 int ndim = icGetSpaceSamples(pProfile->m_Header.colorSpace);
137 int ndim1 = ndim+1;
138
139 // determine granularity
140 if (!nGran) {
15
Assuming 'nGran' is not equal to 0
16
Taking false branch
141 CIccTag* tag = pProfile->FindTag(icSigAToB0Tag + (nIntent == icAbsoluteColorimetric ? icRelativeColorimetric : nIntent));
142
143 if (!tag) {
144 std::cerr << "Tag is nullptr!" << std::endl;
145 return icCmmStatColorNotFound;
146 }
147
148 try {
149 if (dynamic_cast<CIccTagLut16*>(tag) != nullptr) {
150 std::cerr << "Unexpected object type detected!" << std::endl;
151 // If there's a method to get more details about the tag, use it. If not, skip this line.
152 // std::cerr << "Tag details: " << tag->GetDetails() << std::endl;
153 std::cerr << "Actual object type: " << typeid(*tag).name() << std::endl;
154 } else {
155 std::cerr << "Tag is not of expected type!" << std::endl;
156 std::cerr << "Actual object type: " << typeid(*tag).name() << std::endl;
157 }
158 } catch (const std::bad_typeid& e) {
159 std::cerr << "Caught bad_typeid exception: " << e.what() << std::endl;
160 return icCmmStatBadLutType;
161 }
162
163 CIccTagLutAtoB* pTag = dynamic_cast<CIccTagLutAtoB*>(tag);
164
165 // Check if pTag is valid. If it's not, we set nGran to default value and skip further checks.
166 if (!pTag || ndim == 3) {
167 nGran = 33;
168 } else {
169 CIccCLUT* pClut = pTag->GetCLUT();
170 nGran = pClut ? (pClut->GridPoints() + 2) : 33;
171 }
172 }
173
174 int i, j;
175 icFloatNumber stepsize = (icFloatNumber)(1.0/(icFloatNumber)(nGran-1));
176 icFloatNumber* steps = new icFloatNumber[ndim1];
17
Memory is allocated
177 icFloatNumber nstart = 0.0;
178 icFloatNumber nEnd = (icFloatNumber)(1.0+stepsize/2.0);
179 for(j=0; j<ndim1; j++) {
18
Assuming 'j' is < 'ndim1'
19
Loop condition is true. Entering loop body
20
Assuming 'j' is >= 'ndim1'
21
Loop condition is false. Execution continues on line 183
180 steps[j] = nstart;
181 }
182
183 while(steps[0]==nstart) {
22
Loop condition is false. Execution continues on line 207
184 for(j=0; j<ndim; j++) {
185 sPixel[j] = icMin(steps[j+1],1.0);
186 }
187 steps[ndim] = (steps[ndim]+stepsize);
188 for(i=ndim; i>=0; i--) {
189 if(steps[i]>nEnd) {
190 steps[i] = nstart;
191 steps[i-1] = (steps[i-1]+stepsize);
192 }
193 else break;
194 }
195
196 dev2Lab.Apply(devPcs, sPixel); //Convert device value to pcs from input table
197 Lab2Dev2Lab.Apply(roundPcs1, devPcs); //First round trip gets color into output gamut
198 Lab2Dev2Lab.Apply(roundPcs2, roundPcs1); //Second round trip find reproducibility error
199
200 icLabFromPcs(devPcs);
201 icLabFromPcs(roundPcs1);
202 icLabFromPcs(roundPcs2);
203
204 Compare(sPixel, devPcs, roundPcs1, roundPcs2);
205 }
206
207 return icCmmStatOk;
23
Potential leak of memory pointed to by 'steps'
208}
209
210icStatusCMM CIccEvalCompare::EvaluateProfile(const icChar *szProfilePath, icUInt8Number nGrid/* =0 */, icRenderingIntent nIntent/* =icUnknownIntent */,
211 icXformInterp nInterp/* =icInterpLinear */, bool buseMpeTags/* =true */)
212{
213 CIccProfile *pProfile = ReadIccProfile(szProfilePath);
214
215 if (!pProfile)
1
Assuming 'pProfile' is non-null
2
Taking false branch
216 return icCmmStatCantOpenProfile;
217
218 icStatusCMM result = EvaluateProfile(pProfile, nGrid, nIntent, nInterp, buseMpeTags);
3
Calling 'CIccEvalCompare::EvaluateProfile'
219
220 delete pProfile;
221
222 return result;
223}
224
225#ifdef USEREFICCMAXNAMESPACE
226} //namespace refIccMAX
227#endif