diff --git a/IccConnect/IccLibConnect/IccCmmConfig.cpp b/IccConnect/IccLibConnect/IccCmmConfig.cpp index 1e0dc23ea..51e19923f 100644 --- a/IccConnect/IccLibConnect/IccCmmConfig.cpp +++ b/IccConnect/IccLibConnect/IccCmmConfig.cpp @@ -331,11 +331,11 @@ void CIccCfgDataApply::toJson(json& j) const j["srcSpace"] = icGetColorSigStr(buf, 30, m_srcSpace); } - if (m_srcFile.size()) + if (m_srcFile.size() != size_t(0)) j["srcFile"] = m_srcFile; jsonSetValue(j, "dstType", m_dstType); - if (m_dstFile.size()) + if (m_dstFile.size() != size_t(0)) j["dstFile"] = m_dstFile; if (m_dstEncoding != icEncodeValue) @@ -460,9 +460,9 @@ bool CIccCfgImageApply::fromJson(json j, bool bReset) void CIccCfgImageApply::toJson(json& j) const { - if (m_srcImgFile.size()) + if (m_srcImgFile.size() != size_t(0)) j["srcImageFile"] = m_srcImgFile; - if (m_dstImgFile.size()) + if (m_dstImgFile.size() != size_t(0)) j["dstImageFile"] = m_dstImgFile; if (m_dstEncoding != icEncode8Bit) @@ -599,7 +599,7 @@ bool CIccCfgCreateLink::fromJson(json j, bool bReset) void CIccCfgCreateLink::toJson(json& j) const { - if (m_linkFile.size()) + if (m_linkFile.size() != size_t(0)) j["linkFile"] = m_linkFile; switch (m_linkType) { @@ -778,7 +778,7 @@ static bool jsonFromEnvMap(json& j, const icCmmEnvSigMap& map) void CIccCfgProfile::toJson(json& j) const { - if (m_iccFile.size()) + if (m_iccFile.size() != size_t(0)) j["iccFile"] = m_iccFile; else j["iccFile"] = nullptr; @@ -788,7 +788,7 @@ void CIccCfgProfile::toJson(json& j) const json iccMap; if (jsonFromEnvMap(iccMap, m_iccEnvVars)) j["iccEnvVars"] = iccMap; - if (m_pccFile.size()) + if (m_pccFile.size() != size_t(0)) j["pccFile"] = m_pccFile; json pccMap; if (jsonFromEnvMap(pccMap, m_pccEnvVars)) @@ -1271,11 +1271,11 @@ bool CIccCfgSearchApply::fromJsonInit(json j) void CIccCfgSearchApply::toJson(json& j) const { - if (m_profiles.size()) + if (m_profiles.size() != size_t(0)) toJsonProfiles(j["profileSequence"]); if (m_bInitialized) toJsonInit(j["initial"]); - if (m_pccWeights.size()) + if (m_pccWeights.size() != size_t(0)) toJsonPccWeights(j["pccWeights"]); } @@ -1322,7 +1322,7 @@ class CIccIt8Parser while (!isEOF()) { int c = m_f->get(); if (c < 0) { - if (str.size()) + if (str.size() != size_t(0)) line.push_back(str); if (!line.size()) return false; @@ -1331,7 +1331,7 @@ class CIccIt8Parser else if (c == '\n' || c == '\r') { if (c == '\r' && m_f->peek() == '\n') m_f->get(); - if (str.size() || bHasField) + if ((str.size() != size_t(0)) || bHasField) line.push_back(str); break; } @@ -1349,7 +1349,7 @@ class CIccIt8Parser bool parseNextLine(std::vector& line) { while (parseLine(line)) { - if (line.size()) + if (line.size() != size_t(0)) return true; } return false; @@ -1558,6 +1558,8 @@ typedef std::vector icValueVector; static void setSampleIndex(std::vector& samples, int index, const char* szFmt, const char** szChannels) { + if (samples.size() < 1) + return; size_t nPos = samples.size() - 1; for (size_t i = 0; i < samples[nPos].size(); i++) { if (!strcmp(szFmt, szChannels[i])) { @@ -1702,9 +1704,11 @@ bool CIccCfgColorData::fromIt8(const char* filename, bool bReset) if (szFmt) { szFmt++; size_t nChannel = (size_t)atoi(szFmt); - size_t last = samples.size() - 1; - if (nChannel > 0 && samples[last].size() >= nChannel) { - samples[samples.size() - 1][nChannel - 1].nIndex = index; + if (samples.size() > 1) { + size_t last = samples.size() - 1; + if (nChannel > 0 && samples[last].size() >= nChannel) { + samples[samples.size() - 1][nChannel - 1].nIndex = index; + } } } } @@ -1830,7 +1834,10 @@ bool CIccCfgColorData::fromIt8(const char* filename, bool bReset) } } - if (pData->m_values.size() || pData->m_srcValues.size() || pData->m_name.size() || pData->m_srcName.size()) + if ( pData->m_values.size() != size_t(0) + || pData->m_srcValues.size() != size_t(0) + || pData->m_name.size() != size_t(0) + || pData->m_srcName.size() != size_t(0)) m_data.push_back(pData); else pData.reset(); @@ -1924,7 +1931,7 @@ bool CIccCfgColorData::toLegacy(const char* filename, const CIccCfgProfileArray CIccCfgProfile* pProf = pIter->get(); if (!pProf) continue; - if (pProf->m_pccFile.size()) { + if (pProf->m_pccFile.size() != size_t(0)) { fprintf(f, "; %s -PCC %s\n", pProf->m_iccFile.c_str(), pProf->m_pccFile.c_str()); } else { @@ -1938,13 +1945,13 @@ fprintf(f, "\n"); if (!pData) continue; - if (bShowDebug && pData->m_debugInfo.size()) { + if (bShowDebug && pData->m_debugInfo.size() != size_t(0)) { for (auto l = pData->m_debugInfo.begin(); l != pData->m_debugInfo.end(); l++) { fprintf(f, "; %s\n", l->c_str()); } } - if (pData->m_name.size()) { + if (pData->m_name.size() != size_t(0)) { fprintf(f, "{ \"%s\" }\t;", pData->m_name.c_str()); } else { @@ -1954,7 +1961,7 @@ fprintf(f, "\n"); fprintf(f, "\t;"); } - if (pData->m_srcName.size()) { + if (pData->m_srcName.size() != size_t(0)) { fprintf(f,"{ \"%s\" }", pData->m_srcName.c_str()); if (pData->m_srcValues.size() && pData->m_srcValues[0] != 1.0) { if (!writeFloat(pData->m_srcValues[0])) { if (f != stdout) fclose(f); return false; } @@ -2074,7 +2081,7 @@ void CIccCfgColorData::addFields(std::string& dataFormat, int& nFields, int& nSa bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt8Number nPrecision) { - if (!m_data.size()) + if (m_data.size() == size_t(0)) return false; FILE* f; @@ -2101,7 +2108,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt bShowIndex = true; } - if (pEntry->m_label.size()) { + if (pEntry->m_label.size() != size_t(0)) { if (nFields) dataFormat+="\t"; dataFormat += "SAMPLE_ID"; nFields++; @@ -2110,7 +2117,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt bool bSameSpace = spaceName(m_space) == spaceName(m_srcSpace); - if (pEntry->m_name.size()) { + if (pEntry->m_name.size() != size_t(0)) { if (nFields) dataFormat += "\t"; dataFormat += "NAME"; nFields++; @@ -2123,7 +2130,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt bShowValues = true; } - if (pEntry->m_srcName.size()) { + if (pEntry->m_srcName.size() != size_t(0)) { if (nFields) dataFormat += "\t"; if (bSameSpace) dataFormat += "SRC_"; @@ -2174,7 +2181,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt } if (bShowLabel) { - if (line.size()) line += "\t"; + if (line.size() != size_t(0)) line += "\t"; if (!pCurEntry->m_label.size()) line += "\"\""; else @@ -2182,7 +2189,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt } if (bShowName) { - if (line.size()) line += "\t"; + if (line.size() != size_t(0)) line += "\t"; if (!pCurEntry->m_name.size()) line += "\"\""; else @@ -2190,7 +2197,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt } if (bShowValues) { - if (line.size()) line += "\t"; + if (line.size() != size_t(0)) line += "\t"; for (size_t i = 0; i < (size_t)nDstSamples; i++) { icFloatNumber v = (i >= pCurEntry->m_values.size()) ? 0 : pCurEntry->m_values[i]; if (!icFormatFloatValue(buf, bufSize, nDigits, nPrecision, v)) { @@ -2204,7 +2211,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt } if (bShowSrcName) { - if (line.size()) line += "\t"; + if (line.size() != size_t(0)) line += "\t"; if (!pCurEntry->m_srcName.size()) line += "\"\""; else @@ -2212,7 +2219,7 @@ bool CIccCfgColorData::toIt8(const char* filename, icUInt8Number nDigits, icUInt } if (bShowSrcValues) { - if (line.size()) line += "\t"; + if (line.size() != size_t(0)) line += "\t"; for (size_t i = 0; i < (size_t)nSrcSamples; i++) { icFloatNumber v = (i >= pCurEntry->m_srcValues.size()) ? 0 : pCurEntry->m_srcValues[i]; if (!icFormatFloatValue(buf, bufSize, nDigits, nPrecision, v)) { @@ -2255,7 +2262,7 @@ void CIccCfgColorData::toJson(json& obj) const if (entry.is_object()) data.push_back(entry); } - if (data.is_array() && data.size()) { + if (data.is_array() && data.size() != size_t(0)) { obj["data"] = data; } } @@ -2300,23 +2307,23 @@ bool CIccCfgDataEntry::fromJson(json j, bool bReset) void CIccCfgDataEntry::toJson(json& obj) { - if (m_name.size()) + if (m_name.size() != size_t(0)) obj["n"] = m_name; - if (m_values.size()) + if (m_values.size() != size_t(0)) obj["v"] = m_values; - if (m_srcName.size()) + if (m_srcName.size() != size_t(0)) obj["sn"] = m_srcName; - if (m_srcValues.size()) + if (m_srcValues.size() != size_t(0)) obj["sv"] = m_srcValues; - if (m_label.size()) + if (m_label.size() != size_t(0)) obj["l"] = m_label; if (m_index >= 0) obj["i"] = m_index; - if (m_debugInfo.size()) + if (m_debugInfo.size() != size_t(0)) obj["d"] = m_debugInfo; } diff --git a/IccConnect/IccLibConnect/IccJsonUtil.cpp b/IccConnect/IccLibConnect/IccJsonUtil.cpp index 1a8aa2ab2..95a02eb3e 100644 --- a/IccConnect/IccLibConnect/IccJsonUtil.cpp +++ b/IccConnect/IccLibConnect/IccJsonUtil.cpp @@ -429,7 +429,7 @@ bool jsonToColorSpace(const json& j, icColorSpaceSignature& sig) { std::string str; if (jsonToValue(j, str)) { - if (str.size()) + if (str.size() != size_t(0)) sig = (icColorSpaceSignature)icGetSigVal(str.c_str()); else sig = icSigUnknownData; diff --git a/IccProfLib/IccCmm.cpp b/IccProfLib/IccCmm.cpp index 7c25d2e4a..82d556104 100644 --- a/IccProfLib/IccCmm.cpp +++ b/IccProfLib/IccCmm.cpp @@ -343,8 +343,10 @@ bool CIccCreateXformHintManager::AddHint(IIccCreateXformHint* pHint) { if (!m_pList) { m_pList = new (std::nothrow) IIccCreateXformHintList; - if (!m_pList) + if (!m_pList) { + delete pHint; // don't leave the pointer hanging return false; + } } if (pHint) { @@ -825,7 +827,6 @@ CIccXform *CIccXform::Create(CIccProfile *pProfile, if (pHintManager) { pHintManager->AddHint(pNamedColorHint); rv = CIccXformCreator::CreateXform(icXformTypeNamedColor, pTag, pHintManager); -// pHintManager->DeleteHint(pNamedColorHint); // hint manager takes ownership, we should not delete } else { CIccCreateXformHintManager HintManager; @@ -1444,79 +1445,84 @@ icStatusCMM CIccXform::Begin() } // set up for any needed PCS adjustment - if (m_nIntent == icAbsoluteColorimetric && - (m_MediaXYZ.X != illXYZ.X || - m_MediaXYZ.Y != illXYZ.Y || - m_MediaXYZ.Z != illXYZ.Z)) { - - icColorSpaceSignature Space = m_pProfile->m_Header.pcs; - - if (IsSpacePCS(Space)) { - m_bAdjustPCS = true; // turn ON PCS adjustment - - // scale factors depend upon media white point - // set up for input transform - if (!m_bInput) { - m_PCSScale[0] = illumXYZ[0] / mediaXYZ[0]; - m_PCSScale[1] = illumXYZ[1] / mediaXYZ[1]; - m_PCSScale[2] = illumXYZ[2] / mediaXYZ[2]; - } - else { - m_PCSScale[0] = mediaXYZ[0] / illumXYZ[0]; - m_PCSScale[1] = mediaXYZ[1] / illumXYZ[1]; - m_PCSScale[2] = mediaXYZ[2] / illumXYZ[2]; + if (m_nIntent == icAbsoluteColorimetric && + (m_MediaXYZ.X != illXYZ.X || + m_MediaXYZ.Y != illXYZ.Y || + m_MediaXYZ.Z != illXYZ.Z)) { - } + icColorSpaceSignature Space = m_pProfile->m_Header.pcs; - m_PCSOffset[0] = 0.0; - m_PCSOffset[1] = 0.0; - m_PCSOffset[2] = 0.0; - } - } - else if (m_nIntent == icPerceptual && (IsVersion2() || !HasPerceptualHandling())) { - icColorSpaceSignature Space = m_pProfile->m_Header.pcs; + if (IsSpacePCS(Space)) { + m_bAdjustPCS = true; // turn ON PCS adjustment - if (IsSpacePCS(Space) && m_pProfile->m_Header.deviceClass!=icSigAbstractClass) { - m_bAdjustPCS = true; // turn ON PCS adjustment + // scale factors depend upon media white point + // set up for input transform + if (!m_bInput) { + m_PCSScale[0] = illumXYZ[0] / mediaXYZ[0]; + m_PCSScale[1] = illumXYZ[1] / mediaXYZ[1]; + m_PCSScale[2] = illumXYZ[2] / mediaXYZ[2]; + } + else { + m_PCSScale[0] = mediaXYZ[0] / illumXYZ[0]; + m_PCSScale[1] = mediaXYZ[1] / illumXYZ[1]; + m_PCSScale[2] = mediaXYZ[2] / illumXYZ[2]; + } + + if (m_PCSScale[0] == 0.0f || m_PCSScale[1] == 0.0f || m_PCSScale[2] == 0.0f) + return icCmmStatInvalidProfile; - // set up for input transform, which needs version 2 black point to version 4 - m_PCSScale[0] = (icFloatNumber) (1.0 - icPerceptualRefBlackX / icPerceptualRefWhiteX); // scale factors - m_PCSScale[1] = (icFloatNumber) (1.0 - icPerceptualRefBlackY / icPerceptualRefWhiteY); - m_PCSScale[2] = (icFloatNumber) (1.0 - icPerceptualRefBlackZ / icPerceptualRefWhiteZ); + m_PCSOffset[0] = 0.0; + m_PCSOffset[1] = 0.0; + m_PCSOffset[2] = 0.0; + } + } + else if (m_nIntent == icPerceptual && (IsVersion2() || !HasPerceptualHandling())) { + icColorSpaceSignature Space = m_pProfile->m_Header.pcs; - m_PCSOffset[0] = (icFloatNumber) (icPerceptualRefBlackX * 32768.0 / 65535.0); // offset factors - m_PCSOffset[1] = (icFloatNumber) (icPerceptualRefBlackY * 32768.0 / 65535.0); - m_PCSOffset[2] = (icFloatNumber) (icPerceptualRefBlackZ * 32768.0 / 65535.0); + if (IsSpacePCS(Space) && m_pProfile->m_Header.deviceClass!=icSigAbstractClass) { + m_bAdjustPCS = true; // turn ON PCS adjustment - if (!m_bInput) { // output transform must convert version 4 black point to version 2 - m_PCSScale[0] = (icFloatNumber) 1.0 / m_PCSScale[0]; // invert scale factors - m_PCSScale[1] = (icFloatNumber) 1.0 / m_PCSScale[1]; - m_PCSScale[2] = (icFloatNumber) 1.0 / m_PCSScale[2]; + // set up for input transform, which needs version 2 black point to version 4 + m_PCSScale[0] = (icFloatNumber) (1.0 - icPerceptualRefBlackX / icPerceptualRefWhiteX); // scale factors + m_PCSScale[1] = (icFloatNumber) (1.0 - icPerceptualRefBlackY / icPerceptualRefWhiteY); + m_PCSScale[2] = (icFloatNumber) (1.0 - icPerceptualRefBlackZ / icPerceptualRefWhiteZ); + + if (m_PCSScale[0] == 0.0f || m_PCSScale[1] == 0.0f || m_PCSScale[2] == 0.0f) + return icCmmStatInvalidProfile; - m_PCSOffset[0] = - m_PCSOffset[0] * m_PCSScale[0]; // negate offset factors - m_PCSOffset[1] = - m_PCSOffset[1] * m_PCSScale[1]; - m_PCSOffset[2] = - m_PCSOffset[2] * m_PCSScale[2]; - } - } - } + m_PCSOffset[0] = (icFloatNumber) (icPerceptualRefBlackX * 32768.0 / 65535.0); // offset factors + m_PCSOffset[1] = (icFloatNumber) (icPerceptualRefBlackY * 32768.0 / 65535.0); + m_PCSOffset[2] = (icFloatNumber) (icPerceptualRefBlackZ * 32768.0 / 65535.0); + if (!m_bInput) { // output transform must convert version 4 black point to version 2 + m_PCSScale[0] = (icFloatNumber) 1.0 / m_PCSScale[0]; // invert scale factors + m_PCSScale[1] = (icFloatNumber) 1.0 / m_PCSScale[1]; + m_PCSScale[2] = (icFloatNumber) 1.0 / m_PCSScale[2]; - if (m_pAdjustPCS) { - CIccProfile ProfileCopy(*m_pProfile); + m_PCSOffset[0] = - m_PCSOffset[0] * m_PCSScale[0]; // negate offset factors + m_PCSOffset[1] = - m_PCSOffset[1] * m_PCSScale[1]; + m_PCSOffset[2] = - m_PCSOffset[2] * m_PCSScale[2]; + } + } + } - // need to read in all the tags, so that a copy of the profile can be made - if (!ProfileCopy.ReadTags(m_pProfile)) { - return icCmmStatInvalidProfile; - } + + if (m_pAdjustPCS) { + CIccProfile ProfileCopy(*m_pProfile); + + // need to read in all the tags, so that a copy of the profile can be made + if (!ProfileCopy.ReadTags(m_pProfile)) { + return icCmmStatInvalidProfile; + } - if (!m_pAdjustPCS->CalcFactors(&ProfileCopy, this, m_PCSScale, m_PCSOffset)) { - return icCmmStatIncorrectApply; - } + if (!m_pAdjustPCS->CalcFactors(&ProfileCopy, this, m_PCSScale, m_PCSOffset)) { + return icCmmStatIncorrectApply; + } - m_bAdjustPCS = true; - delete m_pAdjustPCS; - m_pAdjustPCS = NULL; - } + m_bAdjustPCS = true; + delete m_pAdjustPCS; + m_pAdjustPCS = NULL; + } return icCmmStatOk; } @@ -7818,14 +7824,10 @@ CIccApplyCmm::~CIccApplyCmm() // if (m_pPCS) // delete m_pPCS; - if (m_Pixel) - free(m_Pixel); - if (m_Pixel2) - free(m_Pixel2); - if (m_ChunkBuf[0]) - free(m_ChunkBuf[0]); - if (m_ChunkBuf[1]) - free(m_ChunkBuf[1]); + free(m_Pixel); + free(m_Pixel2); + free(m_ChunkBuf[0]); + free(m_ChunkBuf[1]); } // Chunk size for transform-sequential multi-pixel apply (pixels per batch). @@ -11305,8 +11307,7 @@ CIccMruCache::~CIccMruCache() if (m_cache) delete[] m_cache; - if (m_pixelData) - free(m_pixelData); + free(m_pixelData); } /** diff --git a/IccProfLib/IccMatrixMath.cpp b/IccProfLib/IccMatrixMath.cpp index f377930df..2ff2179f2 100644 --- a/IccProfLib/IccMatrixMath.cpp +++ b/IccProfLib/IccMatrixMath.cpp @@ -373,7 +373,7 @@ bool CIccMatrixMath::SetRange(const icSpectralRange &srcRange, const icSpectralR icFloatNumber srcScale = (srcEnd - srcStart) / (srcRange.steps-1); icFloatNumber dstScale = (dstEnd - dstStart ) / (dstRange.steps - 1); - if (!std::isfinite(srcScale) || !std::isfinite(dstScale)) + if (!std::isfinite(srcScale) || !std::isfinite(dstScale) || srcScale == 0.0f) return false; icFloatNumber *data=entry(0); diff --git a/IccProfLib/IccMpeACS.cpp b/IccProfLib/IccMpeACS.cpp index 8dcf34cf6..62bab9d8e 100644 --- a/IccProfLib/IccMpeACS.cpp +++ b/IccProfLib/IccMpeACS.cpp @@ -110,8 +110,7 @@ CIccMpeAcs::CIccMpeAcs() ******************************************************************************/ CIccMpeAcs::~CIccMpeAcs() { - if (m_pData) - free(m_pData); + free(m_pData); } /** @@ -304,8 +303,7 @@ icValidateStatus CIccMpeAcs::Validate(std::string sigPath, std::string &sReport, ******************************************************************************/ bool CIccMpeAcs::AllocData(size_t size) { - if (m_pData) - free(m_pData); + free(m_pData); if (size) { m_pData = (icUInt8Number*)malloc(size); diff --git a/IccProfLib/IccMpeBasic.cpp b/IccProfLib/IccMpeBasic.cpp index 2df0799f5..b8bf4f742 100644 --- a/IccProfLib/IccMpeBasic.cpp +++ b/IccProfLib/IccMpeBasic.cpp @@ -153,8 +153,7 @@ CIccFormulaCurveSegment::CIccFormulaCurveSegment(const CIccFormulaCurveSegment & ******************************************************************************/ CIccFormulaCurveSegment &CIccFormulaCurveSegment::operator=(const CIccFormulaCurveSegment &seg) { - if (m_params) - free(m_params); + free(m_params); m_nReserved = seg.m_nReserved; m_nReserved2 = seg.m_nReserved2; @@ -187,9 +186,7 @@ CIccFormulaCurveSegment &CIccFormulaCurveSegment::operator=(const CIccFormulaCur ******************************************************************************/ CIccFormulaCurveSegment::~CIccFormulaCurveSegment() { - if (m_params) { - free(m_params); - } + free(m_params); } /** @@ -339,8 +336,7 @@ void CIccFormulaCurveSegment::Describe(std::string &sDescription, int /* nVerbos ******************************************************************************/ void CIccFormulaCurveSegment::SetFunction(icUInt16Number functionType, icUInt8Number num_parameters, icFloatNumber *parameters) { - if (m_params) - free(m_params); + free(m_params); if (num_parameters) { m_params = (icFloatNumber*)malloc(num_parameters * sizeof(icFloatNumber)); @@ -392,10 +388,8 @@ bool CIccFormulaCurveSegment::Read(size_t size, CIccIO *pIO) if (!pIO->Read16(&m_nReserved2)) return false; - if (m_params) { - free(m_params); - m_params = NULL; - } + free(m_params); + m_params = NULL; switch(m_nFunctionType) { case 0x0000: @@ -926,8 +920,7 @@ CIccSampledCurveSegment::CIccSampledCurveSegment(const CIccSampledCurveSegment & ******************************************************************************/ CIccSampledCurveSegment &CIccSampledCurveSegment::operator=(const CIccSampledCurveSegment &curve) { - if (m_pSamples) - free(m_pSamples); + free(m_pSamples); m_nReserved = curve.m_nReserved; m_startPoint = curve.m_startPoint; @@ -962,8 +955,7 @@ CIccSampledCurveSegment &CIccSampledCurveSegment::operator=(const CIccSampledCur ******************************************************************************/ CIccSampledCurveSegment::~CIccSampledCurveSegment() { - if (m_pSamples) - free(m_pSamples); + free(m_pSamples); } /** @@ -986,18 +978,14 @@ CIccSampledCurveSegment::~CIccSampledCurveSegment() ******************************************************************************/ bool CIccSampledCurveSegment::SetSize(icUInt32Number nCount, bool bZeroAlloc/*=true*/) { + free(m_pSamples); + m_pSamples = NULL; + if (!nCount) { - if (m_pSamples) - free(m_pSamples); - m_pSamples = NULL; m_nCount = nCount; return true; } - if (m_pSamples) { - free(m_pSamples); - } - if (bZeroAlloc) m_pSamples = (icFloatNumber*)calloc(nCount, sizeof(icFloatNumber)); else @@ -1366,8 +1354,7 @@ CIccSingleSampledCurve::CIccSingleSampledCurve(const CIccSingleSampledCurve &cur ******************************************************************************/ CIccSingleSampledCurve &CIccSingleSampledCurve::operator=(const CIccSingleSampledCurve &curve) { - if (m_pSamples) - free(m_pSamples); + free(m_pSamples); m_nReserved = curve.m_nReserved; m_nCount = curve.m_nCount; @@ -1410,8 +1397,7 @@ CIccSingleSampledCurve &CIccSingleSampledCurve::operator=(const CIccSingleSample ******************************************************************************/ CIccSingleSampledCurve::~CIccSingleSampledCurve() { - if (m_pSamples) - free(m_pSamples); + free(m_pSamples); } /** @@ -1507,18 +1493,14 @@ bool CIccSingleSampledCurve::SetStorageType(icUInt16Number nStorateType) ******************************************************************************/ bool CIccSingleSampledCurve::SetSize(icUInt32Number nCount, bool bZeroAlloc/*=true*/) { + free(m_pSamples); + m_pSamples = NULL; + if (!nCount) { - if (m_pSamples) - free(m_pSamples); - m_pSamples = NULL; m_nCount = nCount; return true; } - if (m_pSamples) { - free(m_pSamples); - } - if (bZeroAlloc) m_pSamples = (icFloatNumber*)calloc(nCount, sizeof(icFloatNumber)); else @@ -2032,8 +2014,7 @@ CIccSampledCalculatorCurve &CIccSampledCalculatorCurve::operator=(const CIccSamp delete m_pCalc; } - if (m_pSamples) - free(m_pSamples); + free(m_pSamples); m_nReserved = curve.m_nReserved; m_nReserved2 = curve.m_nReserved2; @@ -2087,8 +2068,7 @@ CIccSampledCalculatorCurve &CIccSampledCalculatorCurve::operator=(const CIccSamp ******************************************************************************/ CIccSampledCalculatorCurve::~CIccSampledCalculatorCurve() { - if (m_pSamples) - free(m_pSamples); + free(m_pSamples); if (m_pCalc) { m_pCalc->SetParentObject(nullptr); @@ -2215,18 +2195,14 @@ bool CIccSampledCalculatorCurve::SetRecommendedSize(icUInt32Number nSize) ******************************************************************************/ bool CIccSampledCalculatorCurve::SetSize(icUInt32Number nCount, bool bZeroAlloc/*=true*/) { + free(m_pSamples); + m_pSamples = NULL; + if (nCount<2) { - if (m_pSamples) - free(m_pSamples); - m_pSamples = NULL; m_nCount = nCount; return nCount == 0; } - if (m_pSamples) { - free(m_pSamples); - } - if (bZeroAlloc) m_pSamples = (icFloatNumber*)calloc(nCount, sizeof(icFloatNumber)); else @@ -3067,6 +3043,9 @@ CIccMpeCurveSet::CIccMpeCurveSet(int nSize/*=0*/) m_nInputChannels = m_nOutputChannels = nSize; m_curve = (icCurveSetCurvePtr*)calloc(nSize, sizeof(icCurveSetCurvePtr)); m_position = (icPositionNumber*)calloc(nSize, sizeof(icPositionNumber)); + if (!m_curve || !m_position) { + m_nInputChannels = m_nOutputChannels = 0; + } } else { m_nInputChannels = m_nOutputChannels = 0; @@ -3097,6 +3076,10 @@ CIccMpeCurveSet::CIccMpeCurveSet(const CIccMpeCurveSet &curveSet) m_nInputChannels = m_nOutputChannels = curveSet.m_nInputChannels; m_curve = (icCurveSetCurvePtr*)calloc(m_nInputChannels, sizeof(icCurveSetCurvePtr)); m_position = (icPositionNumber*)calloc(m_nInputChannels, sizeof(icPositionNumber)); + if (!m_curve || !m_position) { + m_nInputChannels = m_nOutputChannels = 0; + return; + } icCurveMap map; for (i=0; iRead16(&m_nReserved2)) return false; - if (m_params) { - free(m_params); - } + free(m_params); m_nParameters = (icUInt8Number)((size - headerSize)/sizeof(icFloatNumber)); @@ -4465,6 +4444,8 @@ void CIccMpeToneMap::SetNumOutputChannels(icUInt16Number nVectorSize) m_nOutputChannels = nVectorSize; if (m_nOutputChannels) { m_pToneFuncs = (CIccToneMapFunc**)calloc(m_nOutputChannels, sizeof(CIccToneMapFunc*)); + if (!m_pToneFuncs) + m_nOutputChannels = 0; } m_nFunc = 0; } @@ -4580,6 +4561,8 @@ bool CIccMpeToneMap::Read(icUInt32Number size, CIccIO* pIO) m_nInputChannels = nInputChannels; SetNumOutputChannels(nOutputChannels); + if (!m_pToneFuncs || m_nOutputChannels == 0) + return false; //setup to read luminance curve based on position icPositionNumber lumPos; @@ -4987,7 +4970,8 @@ CIccMpeMatrix::CIccMpeMatrix(const CIccMpeMatrix &matrix) if(matrix.m_pMatrix) { size_t num = static_cast(m_size) * sizeof(icFloatNumber); m_pMatrix = (icFloatNumber*)malloc(num); - memcpy(m_pMatrix, matrix.m_pMatrix, num); + if (m_pMatrix) + memcpy(m_pMatrix, matrix.m_pMatrix, num); } else m_pMatrix = NULL; @@ -4995,7 +4979,8 @@ CIccMpeMatrix::CIccMpeMatrix(const CIccMpeMatrix &matrix) if (matrix.m_pConstants) { int num = m_nOutputChannels*sizeof(icFloatNumber); m_pConstants = (icFloatNumber*)malloc(num); - memcpy(m_pConstants, matrix.m_pConstants, num); + if (m_pConstants) + memcpy(m_pConstants, matrix.m_pConstants, num); } else m_pConstants = NULL; @@ -5024,25 +5009,25 @@ CIccMpeMatrix &CIccMpeMatrix::operator=(const CIccMpeMatrix &matrix) m_nInputChannels = matrix.m_nInputChannels; m_nOutputChannels = matrix.m_nOutputChannels; - if (m_pMatrix) - free(m_pMatrix); + free(m_pMatrix); m_size = matrix.m_size; if (matrix.m_pMatrix) { size_t num = static_cast(m_size) * sizeof(icFloatNumber); m_pMatrix = (icFloatNumber*)malloc(num); - memcpy(m_pMatrix, matrix.m_pMatrix, num); + if (m_pMatrix) + memcpy(m_pMatrix, matrix.m_pMatrix, num); } else m_pMatrix = NULL; - if (m_pConstants) - free(m_pConstants); + free(m_pConstants); if (matrix.m_pConstants) { int num = m_nOutputChannels*sizeof(icFloatNumber); m_pConstants = (icFloatNumber*)malloc(num); - memcpy(m_pConstants, matrix.m_pConstants, num); + if (m_pConstants) + memcpy(m_pConstants, matrix.m_pConstants, num); } else m_pConstants = NULL; @@ -5064,11 +5049,8 @@ CIccMpeMatrix &CIccMpeMatrix::operator=(const CIccMpeMatrix &matrix) ******************************************************************************/ CIccMpeMatrix::~CIccMpeMatrix() { - if (m_pMatrix) - free(m_pMatrix); - - if (m_pConstants) - free(m_pConstants); + free(m_pMatrix); + free(m_pConstants); } /** @@ -5083,14 +5065,11 @@ CIccMpeMatrix::~CIccMpeMatrix() ******************************************************************************/ bool CIccMpeMatrix::SetSize(icUInt16Number nInputChannels, icUInt16Number nOutputChannels, bool bUseConstants) { - if (m_pMatrix) { - free(m_pMatrix); - m_pMatrix = NULL; - } - if (m_pConstants) { - free(m_pConstants); - m_pConstants = NULL; - } + free(m_pMatrix); + m_pMatrix = NULL; + + free(m_pConstants); + m_pConstants = NULL; m_size = (icUInt32Number)nInputChannels * nOutputChannels; @@ -5102,7 +5081,6 @@ bool CIccMpeMatrix::SetSize(icUInt16Number nInputChannels, icUInt16Number nOutpu if (bUseConstants) { m_pConstants = (icFloatNumber*)calloc(nOutputChannels, sizeof(icFloatNumber)); - if (!m_pConstants) return false; } diff --git a/IccProfLib/IccMpeCalc.cpp b/IccProfLib/IccMpeCalc.cpp index 818fb4d60..6ac7da885 100644 --- a/IccProfLib/IccMpeCalc.cpp +++ b/IccProfLib/IccMpeCalc.cpp @@ -2959,7 +2959,10 @@ CIccCalculatorFunc::CIccCalculatorFunc(const CIccCalculatorFunc &func) if (m_nOps) { m_Op = (SIccCalcOp*)malloc(m_nOps * sizeof(SIccCalcOp)); - memcpy(m_Op, func.m_Op, m_nOps*sizeof(SIccCalcOp)); + if (m_Op) + memcpy(m_Op, func.m_Op, m_nOps*sizeof(SIccCalcOp)); + else + m_nOps = 0; } else m_Op = NULL; @@ -2981,14 +2984,16 @@ CIccCalculatorFunc &CIccCalculatorFunc::operator=(const CIccCalculatorFunc &func m_nReserved= func.m_nReserved; - if (m_Op) - free(m_Op); + free(m_Op); m_nOps = func.m_nOps; if (m_nOps) { m_Op = (SIccCalcOp*)malloc(m_nOps * sizeof(SIccCalcOp)); - memcpy(m_Op, func.m_Op, m_nOps*sizeof(SIccCalcOp)); + if (m_Op) + memcpy(m_Op, func.m_Op, m_nOps*sizeof(SIccCalcOp)); + else + m_nOps = 0; } else m_Op = NULL; @@ -3008,9 +3013,7 @@ CIccCalculatorFunc &CIccCalculatorFunc::operator=(const CIccCalculatorFunc &func ******************************************************************************/ CIccCalculatorFunc::~CIccCalculatorFunc() { - if (m_Op) { - free(m_Op); - } + free(m_Op); } void CIccCalculatorFunc::InsertBlanks(std::string &sDescription, int nBlanks) @@ -3489,10 +3492,8 @@ icFuncParseStatus CIccCalculatorFunc::SetFunction(const char *szFuncDef, std::st ******************************************************************************/ icFuncParseStatus CIccCalculatorFunc::SetFunction(CIccCalcOpList &opList, std::string &sReport) { - if (m_Op) { - free(m_Op); - m_Op = NULL; - } + free(m_Op); + m_Op = NULL; m_nOps = (icUInt32Number)opList.size(); @@ -3501,10 +3502,13 @@ icFuncParseStatus CIccCalculatorFunc::SetFunction(CIccCalcOpList &opList, std::s int j; m_Op = (SIccCalcOp*)calloc(m_nOps , sizeof(SIccCalcOp)); - - for (i=opList.begin(), j=0; i!= opList.end(); i++, j++) { - m_Op[j] = *i; + if (m_Op) { + for (i=opList.begin(), j=0; i!= opList.end(); i++, j++) { + m_Op[j] = *i; + } } + else + m_nOps = 0; } else { return icFuncParseEmptyFunction; @@ -3556,9 +3560,7 @@ bool CIccCalculatorFunc::Read(icUInt32Number size, CIccIO *pIO) if ((icUInt64Number)m_nOps * sizeof(icUInt32Number) * 2 > (icUInt64Number)size - headerSize) return false; - if (m_Op) { - free(m_Op); - } + free(m_Op); if (m_nOps) { m_Op = (SIccCalcOp*)calloc(m_nOps, sizeof(SIccCalcOp)); @@ -5377,9 +5379,7 @@ CIccApplyMpeCalculator::~CIccApplyMpeCalculator() delete m_scratch; } - if (m_temp) { - free(m_temp); - } + free(m_temp); icUInt32Number i; diff --git a/IccProfLib/IccMpeSpectral.cpp b/IccProfLib/IccMpeSpectral.cpp index 69957d8f8..e3d8bd10e 100644 --- a/IccProfLib/IccMpeSpectral.cpp +++ b/IccProfLib/IccMpeSpectral.cpp @@ -141,7 +141,8 @@ CIccMpeSpectralMatrix::CIccMpeSpectralMatrix(const CIccMpeSpectralMatrix &matrix if(matrix.m_pMatrix) { int num = m_size * sizeof(icFloatNumber); m_pMatrix = (icFloatNumber*)malloc(num); - memcpy(m_pMatrix, matrix.m_pMatrix, num); + if (m_pMatrix) + memcpy(m_pMatrix, matrix.m_pMatrix, num); } else m_pMatrix = NULL; @@ -149,7 +150,8 @@ CIccMpeSpectralMatrix::CIccMpeSpectralMatrix(const CIccMpeSpectralMatrix &matrix if (matrix.m_pOffset) { int num = m_Range.steps * sizeof(icFloatNumber); m_pOffset = (icFloatNumber*)malloc(num); - memcpy(m_pOffset, matrix.m_pOffset, num); + if (m_pOffset) + memcpy(m_pOffset, matrix.m_pOffset, num); } else m_pOffset = NULL; @@ -157,7 +159,8 @@ CIccMpeSpectralMatrix::CIccMpeSpectralMatrix(const CIccMpeSpectralMatrix &matrix if (matrix.m_pWhite) { int num = m_Range.steps * sizeof(icFloatNumber); m_pWhite = (icFloatNumber*)malloc(num); - memcpy(m_pWhite, matrix.m_pWhite, num); + if (m_pWhite) + memcpy(m_pWhite, matrix.m_pWhite, num); } else m_pWhite = NULL; @@ -185,36 +188,36 @@ void CIccMpeSpectralMatrix::copyData(const CIccMpeSpectralMatrix &matrix) m_Range = matrix.m_Range; - if (m_pMatrix) - free(m_pMatrix); + free(m_pMatrix); m_size = matrix.m_size; if (matrix.m_pMatrix) { int num = m_size * sizeof(icFloatNumber); m_pMatrix = (icFloatNumber*)malloc(num); - memcpy(m_pMatrix, matrix.m_pMatrix, num); + if (m_pMatrix) + memcpy(m_pMatrix, matrix.m_pMatrix, num); } else m_pMatrix = NULL; - if (m_pOffset) - free(m_pOffset); + free(m_pOffset); if (matrix.m_pOffset) { int num = m_Range.steps * sizeof(icFloatNumber); m_pOffset = (icFloatNumber*)malloc(num); - memcpy(m_pOffset, matrix.m_pOffset, num); + if (m_pOffset) + memcpy(m_pOffset, matrix.m_pOffset, num); } else m_pOffset = NULL; - if (m_pWhite) - free(m_pWhite); + free(m_pWhite); if (matrix.m_pWhite) { int num = m_Range.steps * sizeof(icFloatNumber); m_pWhite = (icFloatNumber*)malloc(num); - memcpy(m_pWhite, matrix.m_pWhite, num); + if (m_pWhite) + memcpy(m_pWhite, matrix.m_pWhite, num); } else m_pWhite = NULL; @@ -234,14 +237,9 @@ void CIccMpeSpectralMatrix::copyData(const CIccMpeSpectralMatrix &matrix) ******************************************************************************/ CIccMpeSpectralMatrix::~CIccMpeSpectralMatrix() { - if (m_pMatrix) - free(m_pMatrix); - - if (m_pOffset) - free(m_pOffset); - - if (m_pWhite) - free(m_pWhite); + free(m_pMatrix); + free(m_pOffset); + free(m_pWhite); if (m_pApplyMtx) delete m_pApplyMtx; @@ -260,20 +258,14 @@ CIccMpeSpectralMatrix::~CIccMpeSpectralMatrix() ******************************************************************************/ bool CIccMpeSpectralMatrix::SetSize(icUInt16Number nInputChannels, icUInt16Number nOutputChannels, const icSpectralRange &range) { - if (m_pMatrix) { - free(m_pMatrix); - m_pMatrix = NULL; - } + free(m_pMatrix); + m_pMatrix = NULL; - if (m_pWhite) { - free(m_pWhite); - m_pWhite = NULL; - } + free(m_pWhite); + m_pWhite = NULL; - if (m_pOffset) { - free(m_pOffset); - m_pOffset = NULL; - } + free(m_pOffset); + m_pOffset = NULL; if (m_pApplyMtx) { delete m_pApplyMtx; @@ -852,7 +844,8 @@ CIccMpeSpectralCLUT::CIccMpeSpectralCLUT(const CIccMpeSpectralCLUT &clut) if (clut.m_pWhite) { m_pWhite = (icFloatNumber *)malloc((int)clut.m_Range.steps*sizeof(icFloatNumber)); - memcpy(m_pWhite, clut.m_pWhite, clut.m_Range.steps*sizeof(icFloatNumber)); + if (m_pWhite) + memcpy(m_pWhite, clut.m_pWhite, clut.m_Range.steps*sizeof(icFloatNumber)); } else m_pWhite = NULL; @@ -884,8 +877,7 @@ void CIccMpeSpectralCLUT::copyData(const CIccMpeSpectralCLUT &clut) if (m_pApplyCLUT) delete m_pApplyCLUT; - if (m_pWhite) - free(m_pWhite); + free(m_pWhite); if (clut.m_pCLUT) m_pCLUT = new CIccCLUT(*clut.m_pCLUT); @@ -899,7 +891,8 @@ void CIccMpeSpectralCLUT::copyData(const CIccMpeSpectralCLUT &clut) if (clut.m_pWhite) { m_pWhite = (icFloatNumber *)malloc((int)clut.m_Range.steps*sizeof(icFloatNumber)); - memcpy(m_pWhite, clut.m_pWhite, clut.m_Range.steps*sizeof(icFloatNumber)); + if (m_pWhite) + memcpy(m_pWhite, clut.m_pWhite, clut.m_Range.steps*sizeof(icFloatNumber)); } else m_pWhite = NULL; @@ -931,8 +924,7 @@ CIccMpeSpectralCLUT::~CIccMpeSpectralCLUT() if (m_pApplyCLUT) delete m_pApplyCLUT; - if (m_pWhite) - free(m_pWhite); + free(m_pWhite); } @@ -969,8 +961,7 @@ void CIccMpeSpectralCLUT::SetData(CIccCLUT *pCLUT, icUInt16Number nStorageType, m_Range = range; - if (m_pWhite) - free(m_pWhite); + free(m_pWhite); m_pWhite = pWhite; } @@ -1711,7 +1702,8 @@ CIccMpeSpectralObserver::CIccMpeSpectralObserver(const CIccMpeSpectralObserver & if (matrix.m_pWhite) { int num = m_Range.steps*sizeof(icFloatNumber); m_pWhite = (icFloatNumber*)malloc(num); - memcpy(m_pWhite, matrix.m_pWhite, num); + if (m_pWhite) + memcpy(m_pWhite, matrix.m_pWhite, num); } else m_pWhite = NULL; @@ -1738,13 +1730,13 @@ void CIccMpeSpectralObserver::copyData(const CIccMpeSpectralObserver &matrix) m_Range = matrix.m_Range; - if (m_pWhite) - free(m_pWhite); + free(m_pWhite); if (matrix.m_pWhite) { int num = m_Range.steps*sizeof(icFloatNumber); m_pWhite = (icFloatNumber*)malloc(num); - memcpy(m_pWhite, matrix.m_pWhite, num); + if (m_pWhite) + memcpy(m_pWhite, matrix.m_pWhite, num); } else m_pWhite = NULL; @@ -1764,8 +1756,7 @@ void CIccMpeSpectralObserver::copyData(const CIccMpeSpectralObserver &matrix) ******************************************************************************/ CIccMpeSpectralObserver::~CIccMpeSpectralObserver() { - if (m_pWhite) - free(m_pWhite); + free(m_pWhite); if (m_pApplyMtx) delete m_pApplyMtx; @@ -1784,10 +1775,8 @@ CIccMpeSpectralObserver::~CIccMpeSpectralObserver() ******************************************************************************/ bool CIccMpeSpectralObserver::SetSize(icUInt16Number nInputChannels, icUInt16Number nOutputChannels, const icSpectralRange &range) { - if (m_pWhite) { - free(m_pWhite); - m_pWhite = NULL; - } + free(m_pWhite); + m_pWhite = NULL; if (m_pApplyMtx) { delete m_pApplyMtx; diff --git a/IccProfLib/IccProfile.cpp b/IccProfLib/IccProfile.cpp index 337ba0929..81c3cf669 100644 --- a/IccProfLib/IccProfile.cpp +++ b/IccProfLib/IccProfile.cpp @@ -3766,7 +3766,7 @@ CIccProfile* ValidateIccProfile(CIccIO *pIO, std::string &sReport, icValidateSta return NULL; } - CIccProfile *pIcc = new CIccProfile; + CIccProfile *pIcc = new (std::nothrow) CIccProfile; if (!pIcc) { delete pIO; diff --git a/IccProfLib/IccTagBasic.cpp b/IccProfLib/IccTagBasic.cpp index f38a6d6a3..bb5c73e93 100644 --- a/IccProfLib/IccTagBasic.cpp +++ b/IccProfLib/IccTagBasic.cpp @@ -563,8 +563,12 @@ void CIccTagUnknown::Describe(std::string &sDescription, int nVerboseness) CIccTagText::CIccTagText() { m_szText = (icChar*)malloc(1); - m_szText[0] = '\0'; - m_nBufSize = 1; + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + } + else + m_nBufSize = 0; } /** @@ -580,9 +584,13 @@ CIccTagText::CIccTagText() CIccTagText::CIccTagText(const CIccTagText &ITT) { m_szText = (icChar*)malloc(1); - m_szText[0] = '\0'; - m_nBufSize = 1; - SetText(ITT.m_szText); + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + SetText(ITT.m_szText); + } + else + m_nBufSize = 0; } /** @@ -601,9 +609,13 @@ CIccTagText &CIccTagText::operator=(const CIccTagText &TextTag) return *this; m_szText = (icChar*)malloc(1); - m_szText[0] = '\0'; - m_nBufSize = 1; - SetText(TextTag.m_szText); + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + SetText(TextTag.m_szText); + } + else + m_nBufSize = 0; return *this; } @@ -807,7 +819,6 @@ icChar *CIccTagText::GetBuffer(icUInt32Number nSize) { if (m_nBufSize < nSize) { m_szText = (icChar*)icRealloc(m_szText, nSize+1); - if (m_szText) { m_szText[nSize] = '\0'; m_nBufSize = nSize; @@ -833,7 +844,10 @@ void CIccTagText::Release() if (nSize < m_nBufSize-1) { m_szText=(icChar*)icRealloc(m_szText, nSize+1); - m_nBufSize = nSize+1; + if (m_szText) + m_nBufSize = nSize+1; + else + m_nBufSize = 0; } } @@ -912,8 +926,12 @@ icValidateStatus CIccTagText::Validate(std::string sigPath, std::string &sReport CIccTagUtf8Text::CIccTagUtf8Text() { m_szText = (icUChar*)malloc(1); - m_szText[0] = '\0'; - m_nBufSize = 1; + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + } + else + m_nBufSize = 0; } /** @@ -929,9 +947,13 @@ CIccTagUtf8Text::CIccTagUtf8Text() CIccTagUtf8Text::CIccTagUtf8Text(const CIccTagUtf8Text &ITT) { m_szText = (icUChar*)malloc(1); - m_szText[0] = '\0'; - m_nBufSize = 1; - SetText(ITT.m_szText); + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + SetText(ITT.m_szText); + } + else + m_nBufSize = 0; } /** @@ -950,9 +972,14 @@ CIccTagUtf8Text &CIccTagUtf8Text::operator=(const CIccTagUtf8Text &TextTag) return *this; m_szText = (icUChar*)malloc(1); - m_szText[0] = '\0'; - m_nBufSize = 1; SetText(TextTag.m_szText); + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + SetText(TextTag.m_szText); + } + else + m_nBufSize = 0; return *this; } @@ -1186,7 +1213,6 @@ icUChar *CIccTagUtf8Text::GetBuffer(icUInt32Number nSize) { if (m_nBufSize < nSize) { m_szText = (icUChar*)icRealloc(m_szText, nSize+1); - if (m_szText) { m_szText[nSize] = '\0'; m_nBufSize = nSize; @@ -1213,7 +1239,10 @@ void CIccTagUtf8Text::Release() if (nSize < m_nBufSize-1) { m_szText=(icUChar*)icRealloc(m_szText, nSize+1); - m_nBufSize = nSize+1; + if (m_szText) + m_nBufSize = nSize+1; + else + m_nBufSize = 0; } } @@ -1321,8 +1350,7 @@ CIccTagZipUtf8Text &CIccTagZipUtf8Text::operator=(const CIccTagZipUtf8Text &ITT) */ CIccTagZipUtf8Text::~CIccTagZipUtf8Text() { - if (m_pZipBuf) - free(m_pZipBuf); + free(m_pZipBuf); } /** @@ -1632,12 +1660,9 @@ icUChar *CIccTagZipUtf8Text::AllocBuffer(icUInt32Number nSize) { if (m_nBufSize != nSize) { if (!nSize) { - if (m_pZipBuf) { - free(m_pZipBuf); - m_pZipBuf = NULL; - } - - m_nBufSize = nSize; + free(m_pZipBuf); + m_pZipBuf = NULL; + m_nBufSize = 0; return NULL; } @@ -1646,8 +1671,10 @@ icUChar *CIccTagZipUtf8Text::AllocBuffer(icUInt32Number nSize) else m_pZipBuf = (icUChar*)icRealloc(m_pZipBuf, nSize); - m_nBufSize = nSize; - + if (m_pZipBuf) + m_nBufSize = nSize; + else + m_nBufSize = 0; } return m_pZipBuf; @@ -1722,8 +1749,12 @@ icValidateStatus CIccTagZipUtf8Text::Validate(std::string sigPath, std::string & CIccTagUtf16Text::CIccTagUtf16Text() { m_szText = (icUChar16*)malloc(1*sizeof(icUChar16)); - m_szText[0] = 0; - m_nBufSize = 1; + if (m_szText) { + m_szText[0] = 0; + m_nBufSize = 1; + } + else + m_nBufSize = 0; } /** @@ -1739,9 +1770,13 @@ CIccTagUtf16Text::CIccTagUtf16Text() CIccTagUtf16Text::CIccTagUtf16Text(const CIccTagUtf16Text &ITT) { m_szText = (icUChar16*)malloc(1*sizeof(icUChar16)); - m_szText[0] = 0; - m_nBufSize = 1; - SetText(ITT.m_szText); + if (m_szText) { + m_szText[0] = 0; + m_nBufSize = 1; + SetText(ITT.m_szText); + } + else + m_nBufSize = 0; } /** @@ -1760,9 +1795,13 @@ CIccTagUtf16Text &CIccTagUtf16Text::operator=(const CIccTagUtf16Text &TextTag) return *this; m_szText = (icUChar16*)malloc(1*sizeof(icUChar16)); - m_szText[0] = '\0'; - m_nBufSize = 1; - SetText(TextTag.m_szText); + if (m_szText) { + m_szText[0] = '\0'; + m_nBufSize = 1; + SetText(TextTag.m_szText); + } + else + m_nBufSize = 0; return *this; } @@ -2064,10 +2103,13 @@ icUChar16 *CIccTagUtf16Text::GetBuffer(icUInt32Number nSize) { if (m_nBufSize < nSize) { m_szText = (icUChar16*)icRealloc(m_szText, (nSize+1)*sizeof(icUChar16)); - - m_szText[nSize] = 0; - - m_nBufSize = nSize; + if (m_szText) { + m_szText[nSize] = 0; + m_nBufSize = nSize; + } + else { + m_nBufSize = 0; + } } return m_szText; @@ -2087,7 +2129,10 @@ void CIccTagUtf16Text::Release() if (nSize < m_nBufSize-1) { m_szText=(icUChar16*)icRealloc(m_szText, (nSize+1)*sizeof(icUChar16)); - m_nBufSize = nSize+1; + if (m_szText) + m_nBufSize = nSize+1; + else + m_nBufSize = 0; } } @@ -2136,12 +2181,20 @@ icValidateStatus CIccTagUtf16Text::Validate(std::string sigPath, std::string &sR CIccTagTextDescription::CIccTagTextDescription() { m_szText = (icChar*)malloc(1); - m_szText[0] = '\0'; - m_nASCIISize = 1; + if (m_szText) { + m_szText[0] = 0; + m_nASCIISize = 1; + } + else + m_nASCIISize = 0; m_uzUnicodeText = (icUInt16Number*)malloc(sizeof(icUInt16Number)); - m_uzUnicodeText[0] = 0; - m_nUnicodeSize = 1; + if (m_uzUnicodeText) { + m_uzUnicodeText[0] = 0; + m_nUnicodeSize = 1; + } else + m_nUnicodeSize = 0; + m_nUnicodeLanguageCode = 0; m_nScriptSize = 0; @@ -2171,22 +2224,34 @@ CIccTagTextDescription::CIccTagTextDescription(const CIccTagTextDescription &ITT if (m_nASCIISize) { m_szText = (icChar*)malloc(m_nASCIISize * sizeof(icChar)); - memcpy(m_szText, ITTD.m_szText, m_nASCIISize*sizeof(icChar)); + if (m_szText) + memcpy(m_szText, ITTD.m_szText, m_nASCIISize*sizeof(icChar)); + else + m_nASCIISize = 0; } else { m_nASCIISize = 1; m_szText = (icChar*)calloc(m_nASCIISize, sizeof(icChar)); - m_szText[0] = '\0'; + if (m_szText) + m_szText[0] = '\0'; + else + m_nASCIISize = 0; } if (m_nUnicodeSize) { m_uzUnicodeText = (icUInt16Number*)malloc((m_nUnicodeSize) * sizeof(icUInt16Number)); - memcpy(m_uzUnicodeText, ITTD.m_uzUnicodeText, m_nUnicodeSize*sizeof(icUInt16Number)); + if (m_uzUnicodeText) + memcpy(m_uzUnicodeText, ITTD.m_uzUnicodeText, m_nUnicodeSize*sizeof(icUInt16Number)); + else + m_nUnicodeSize = 0; } else { m_nUnicodeSize = 1; m_uzUnicodeText = (icUInt16Number*)calloc(m_nUnicodeSize, sizeof(icUInt16Number)); - m_uzUnicodeText[0] = 0; + if (m_uzUnicodeText) + m_uzUnicodeText[0] = 0; + else + m_nUnicodeSize = 0; } memcpy(m_szScriptText, ITTD.m_szScriptText, sizeof(m_szScriptText)); @@ -2216,28 +2281,38 @@ CIccTagTextDescription &CIccTagTextDescription::operator=(const CIccTagTextDescr m_nScriptSize = TextDescTag.m_nScriptSize; m_nScriptCode = TextDescTag.m_nScriptCode; - if (m_szText) - free(m_szText); + free(m_szText); if (m_nASCIISize) { m_szText = (icChar*)calloc(m_nASCIISize, sizeof(icChar)); - memcpy(m_szText, TextDescTag.m_szText, m_nASCIISize*sizeof(icChar)); - } + if (m_szText) + memcpy(m_szText, TextDescTag.m_szText, m_nASCIISize*sizeof(icChar)); + else + m_nASCIISize = 0; + } else { m_nASCIISize = 1; m_szText = (icChar*)calloc(m_nASCIISize, sizeof(icChar)); - m_szText[0] = '\0'; + if (m_szText) + m_szText[0] = '\0'; + else + m_nASCIISize = 0; } - if (m_uzUnicodeText) - free(m_uzUnicodeText); + free(m_uzUnicodeText); if (m_nUnicodeSize) { m_uzUnicodeText = (icUInt16Number*)calloc(m_nUnicodeSize, sizeof(icUInt16Number)); - memcpy(m_uzUnicodeText, TextDescTag.m_uzUnicodeText, m_nUnicodeSize*sizeof(icUInt16Number)); + if (m_uzUnicodeText) + memcpy(m_uzUnicodeText, TextDescTag.m_uzUnicodeText, m_nUnicodeSize*sizeof(icUInt16Number)); + else + m_nUnicodeSize = 0; } else { m_nUnicodeSize = 1; m_uzUnicodeText = (icUInt16Number*)calloc(m_nUnicodeSize, sizeof(icUInt16Number)); - m_uzUnicodeText[0] = 0; + if (m_uzUnicodeText) + m_uzUnicodeText[0] = 0; + else + m_nUnicodeSize = 0; } memcpy(m_szScriptText, TextDescTag.m_szScriptText, sizeof(m_szScriptText)); @@ -2483,8 +2558,8 @@ void CIccTagTextDescription::SetText(const icChar *szText) icUInt32Number len=(icUInt32Number)strlen(szText) + 1; icChar *szBuf = GetBuffer(len); - - strcpy(szBuf, szText); + if (szBuf) + strcpy(szBuf, szText); Release(); } @@ -2523,10 +2598,12 @@ icChar *CIccTagTextDescription::GetBuffer(icUInt32Number nSize) { if (m_nASCIISize < (nSize+1)) { m_szText = (icChar*)icRealloc(m_szText, (nSize+1)); - - m_szText[nSize] = '\0'; - - m_nASCIISize = (nSize+1); // include NULL termination! + if (m_szText) { + m_szText[nSize] = '\0'; + m_nASCIISize = (nSize+1); // include NULL termination! + } + else + m_nASCIISize = 0; } return m_szText; @@ -2542,12 +2619,18 @@ icChar *CIccTagTextDescription::GetBuffer(icUInt32Number nSize) */ void CIccTagTextDescription::Release() { - icUInt32Number nSize = (icUInt32Number)strlen(m_szText); - - if (nSize < m_nASCIISize-1) { - m_szText=(icChar*)icRealloc(m_szText, nSize+1); - m_nASCIISize = nSize+1; + if (m_szText) { + icUInt32Number nSize = (icUInt32Number)strlen(m_szText); + if (nSize < m_nASCIISize-1) { + m_szText=(icChar*)icRealloc(m_szText, nSize+1); + if (m_szText) + m_nASCIISize = nSize+1; + else + m_nASCIISize = 0; + } } + else + m_nASCIISize = 0; } /** @@ -2567,11 +2650,13 @@ icUInt16Number *CIccTagTextDescription::GetUnicodeBuffer(icUInt32Number nSize) { if (m_nUnicodeSize < (nSize+2)) { // test for existing size must include the NULL termination! m_uzUnicodeText = (icUInt16Number*)icRealloc(m_uzUnicodeText, (nSize+2)*sizeof(icUInt16Number)); - - m_uzUnicodeText[nSize] = 0; - m_uzUnicodeText[nSize+1] = 0; - - m_nUnicodeSize = nSize+2; + if (m_uzUnicodeText) { + m_uzUnicodeText[nSize] = 0; + m_uzUnicodeText[nSize+1] = 0; + m_nUnicodeSize = nSize+2; + } + else + m_nUnicodeSize = 0; } return m_uzUnicodeText; @@ -2597,9 +2682,13 @@ void CIccTagTextDescription::ReleaseUnicode() // but don't reallocate because of the NULLs if (nSize < (m_nUnicodeSize-2)) { m_uzUnicodeText=(icUInt16Number*)icRealloc(m_uzUnicodeText, (nSize+2)*sizeof(icUInt16Number)); - m_uzUnicodeText[nSize] = 0; - m_uzUnicodeText[nSize+1] = 0; - m_nUnicodeSize = nSize+2; + if (m_uzUnicodeText) { + m_uzUnicodeText[nSize] = 0; + m_uzUnicodeText[nSize+1] = 0; + m_nUnicodeSize = nSize+2; + } + else + m_nUnicodeSize = 0; } } @@ -2933,6 +3022,8 @@ CIccTagNamedColor2::CIccTagNamedColor2(int nSize/*=1*/, int nDeviceCoords/*=0*/) m_nColorEntrySize = 32/*rootName*/ + (3/*PCS*/ + 1/*iAny*/ + nDeviceCoords)*sizeof(icFloatNumber); m_NamedColor = (SIccNamedColorEntry*)calloc(nSize, m_nColorEntrySize); + if (!m_NamedColor) + m_nSize = 0; m_NamedLab = NULL; } @@ -2962,7 +3053,10 @@ CIccTagNamedColor2::CIccTagNamedColor2(const CIccTagNamedColor2 &ITNC) memcpy(m_szSufix, ITNC.m_szSufix, sizeof(m_szSufix)); m_NamedColor = (SIccNamedColorEntry*)calloc(m_nSize, m_nColorEntrySize); - memcpy(m_NamedColor, ITNC.m_NamedColor, (size_t)m_nColorEntrySize*m_nSize); + if (m_NamedColor) + memcpy(m_NamedColor, ITNC.m_NamedColor, (size_t)m_nColorEntrySize*m_nSize); + else + m_nSize = 0; m_NamedLab = NULL; } @@ -2994,10 +3088,12 @@ CIccTagNamedColor2 &CIccTagNamedColor2::operator=(const CIccTagNamedColor2 &Name memcpy(m_szPrefix, NamedColor2Tag.m_szPrefix, sizeof(m_szPrefix)); memcpy(m_szSufix, NamedColor2Tag.m_szSufix, sizeof(m_szSufix)); - if (m_NamedColor) - free(m_NamedColor); + free(m_NamedColor); m_NamedColor = (SIccNamedColorEntry*)calloc(m_nSize, m_nColorEntrySize); - memcpy(m_NamedColor, NamedColor2Tag.m_NamedColor, (size_t)m_nColorEntrySize*m_nSize); + if (m_NamedColor) + memcpy(m_NamedColor, NamedColor2Tag.m_NamedColor, (size_t)m_nColorEntrySize*m_nSize); + else + m_nSize = 0; m_NamedLab = NULL; @@ -3015,8 +3111,7 @@ CIccTagNamedColor2 &CIccTagNamedColor2::operator=(const CIccTagNamedColor2 &Name */ CIccTagNamedColor2::~CIccTagNamedColor2() { - if (m_NamedColor) - free(m_NamedColor); + free(m_NamedColor); if (m_NamedLab) delete [] m_NamedLab; @@ -3785,7 +3880,10 @@ CIccTagXYZ::CIccTagXYZ(const CIccTagXYZ &ITXYZ) m_nSize = ITXYZ.m_nSize; m_XYZ = (icXYZNumber*)calloc(m_nSize, sizeof(icXYZNumber)); - memcpy(m_XYZ, ITXYZ.m_XYZ, sizeof(icXYZNumber)*m_nSize); + if (m_XYZ) + memcpy(m_XYZ, ITXYZ.m_XYZ, sizeof(icXYZNumber)*m_nSize); + else + m_nSize = 0; } @@ -3807,10 +3905,12 @@ CIccTagXYZ &CIccTagXYZ::operator=(const CIccTagXYZ &XYZTag) m_nSize = XYZTag.m_nSize; - if (m_XYZ) - free(m_XYZ); + free(m_XYZ); m_XYZ = (icXYZNumber*)calloc(m_nSize, sizeof(icXYZNumber)); - memcpy(m_XYZ, XYZTag.m_XYZ, sizeof(icXYZNumber)*m_nSize); + if (m_XYZ) + memcpy(m_XYZ, XYZTag.m_XYZ, sizeof(icXYZNumber)*m_nSize); + else + m_nSize = 0; return *this; } @@ -3826,8 +3926,7 @@ CIccTagXYZ &CIccTagXYZ::operator=(const CIccTagXYZ &XYZTag) */ CIccTagXYZ::~CIccTagXYZ() { - if (m_XYZ) - free(m_XYZ); + free(m_XYZ); } @@ -3959,8 +4058,13 @@ bool CIccTagXYZ::SetSize(icUInt32Number nSize, bool bZeroNew/*=true*/) if (nSize==m_nSize) return true; - m_XYZ = (icXYZNumber*)icRealloc(m_XYZ, nSize*sizeof(icXYZNumber)); + if (nSize > 65536) { + free(m_XYZ); + m_nSize = 0; + return false; + } + m_XYZ = (icXYZNumber*)icRealloc(m_XYZ, nSize*sizeof(icXYZNumber)); if (!m_XYZ) { m_nSize = 0; return false; @@ -4048,7 +4152,8 @@ CIccTagChromaticity::CIccTagChromaticity(const CIccTagChromaticity &ITCh) m_nChannels = ITCh.m_nChannels; m_xy = (icChromaticityNumber*)calloc(m_nChannels, sizeof(icChromaticityNumber)); - memcpy(m_xy, ITCh.m_xy, sizeof(icChromaticityNumber)*m_nChannels); + if (m_xy) + memcpy(m_xy, ITCh.m_xy, sizeof(icChromaticityNumber)*m_nChannels); } @@ -4069,10 +4174,10 @@ CIccTagChromaticity &CIccTagChromaticity::operator=(const CIccTagChromaticity &C m_nChannels = ChromTag.m_nChannels; - if (m_xy) - free(m_xy); + free(m_xy); m_xy = (icChromaticityNumber*)calloc(m_nChannels, sizeof(icChromaticityNumber)); - memcpy(m_xy, ChromTag.m_xy, sizeof(icChromaticityNumber)*m_nChannels); + if (m_xy) + memcpy(m_xy, ChromTag.m_xy, sizeof(icChromaticityNumber)*m_nChannels); return *this; } @@ -4088,8 +4193,7 @@ CIccTagChromaticity &CIccTagChromaticity::operator=(const CIccTagChromaticity &C */ CIccTagChromaticity::~CIccTagChromaticity() { - if (m_xy) - free(m_xy); + free(m_xy); } @@ -4241,7 +4345,6 @@ bool CIccTagChromaticity::SetSize(icUInt16Number nSize, bool bZeroNew/*=true*/) return true; m_xy = (icChromaticityNumber*)icRealloc(m_xy, nSize*sizeof(icChromaticityNumber)); - if (!m_xy) { m_nChannels = 0; return false; @@ -4684,6 +4787,8 @@ CIccTagSparseMatrixArray::CIccTagSparseMatrixArray(int nNumMatrices/* =1 */, int m_nChannelsPerMatrix = 4; m_RawData = (icUInt8Number*)calloc(m_nSize, GetBytesPerMatrix()); + if (!m_RawData) + m_nSize = 0; m_bNonZeroPadding = false; } @@ -4737,10 +4842,12 @@ CIccTagSparseMatrixArray &CIccTagSparseMatrixArray::operator=(const CIccTagSpars m_nSize = ITSMA.m_nSize; m_nChannelsPerMatrix = ITSMA.m_nChannelsPerMatrix; - if (m_RawData) - free(m_RawData); + free(m_RawData); m_RawData = (icUInt8Number*)calloc(m_nSize, GetBytesPerMatrix()); - memcpy(m_RawData, ITSMA.m_RawData, (size_t)m_nSize*GetBytesPerMatrix()); + if (m_RawData) + memcpy(m_RawData, ITSMA.m_RawData, (size_t)m_nSize*GetBytesPerMatrix()); + else + m_nSize = 0; m_bNonZeroPadding = ITSMA.m_bNonZeroPadding; @@ -4759,8 +4866,7 @@ CIccTagSparseMatrixArray &CIccTagSparseMatrixArray::operator=(const CIccTagSpars */ CIccTagSparseMatrixArray::~CIccTagSparseMatrixArray() { - if (m_RawData) - free(m_RawData); + free(m_RawData); } @@ -5517,6 +5623,8 @@ CIccTagFixedNum::CIccTagFixedNum(int nSize/*=1*/) if (m_nSize <1) m_nSize = 1; m_Num = (T*)calloc(nSize, sizeof(T)); + if (!m_Num) + m_nSize = 0; } @@ -5535,7 +5643,10 @@ CIccTagFixedNum::CIccTagFixedNum(const CIccTagFixedNum &ITFN) { m_nSize = ITFN.m_nSize; m_Num = (T*)calloc(m_nSize, sizeof(T)); - memcpy(m_Num, ITFN.m_Num, m_nSize*sizeof(T)); + if (m_Num) + memcpy(m_Num, ITFN.m_Num, m_nSize*sizeof(T)); + else + m_nSize = 0; } @@ -5557,10 +5668,12 @@ CIccTagFixedNum &CIccTagFixedNum::operator=(const CIccTagFixed m_nSize = ITFN.m_nSize; - if (m_Num) - free(m_Num); + free(m_Num); m_Num = (T*)calloc(m_nSize, sizeof(T)); - memcpy(m_Num, ITFN.m_Num, m_nSize*sizeof(T)); + if (m_Num) + memcpy(m_Num, ITFN.m_Num, m_nSize*sizeof(T)); + else + m_nSize = 0; return *this; } @@ -5578,8 +5691,7 @@ CIccTagFixedNum &CIccTagFixedNum::operator=(const CIccTagFixed template CIccTagFixedNum::~CIccTagFixedNum() { - if (m_Num) - free(m_Num); + free(m_Num); } /** @@ -5741,7 +5853,6 @@ bool CIccTagFixedNum::SetSize(icUInt32Number nSize, bool bZeroNew/*=tru return true; m_Num = (T*)icRealloc(m_Num, nSize*sizeof(T)); - if (!m_Num) { m_nSize = 0; return false; @@ -5978,6 +6089,8 @@ CIccTagNum::CIccTagNum(int nSize/*=1*/) if (m_nSize <1) m_nSize = 1; m_Num = (T*)calloc(nSize, sizeof(T)); + if (!m_Num) + m_nSize = 0; } @@ -5997,7 +6110,10 @@ CIccTagNum::CIccTagNum(const CIccTagNum &ITNum) m_nSize = ITNum.m_nSize; m_Num = (T*)calloc(m_nSize, sizeof(T)); - memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + if (m_Num) + memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + else + m_nSize = 0; } @@ -6020,7 +6136,10 @@ CIccTagNum &CIccTagNum::operator=(const CIccTagNum &I m_nSize = ITNum.m_nSize; m_Num = (T*)calloc(m_nSize, sizeof(T)); - memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + if (m_Num) + memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + else + m_nSize = 0; return *this; } @@ -6038,8 +6157,7 @@ CIccTagNum &CIccTagNum::operator=(const CIccTagNum &I template CIccTagNum::~CIccTagNum() { - if (m_Num) - free(m_Num); + free(m_Num); } /** @@ -6306,7 +6424,6 @@ bool CIccTagNum::SetSize(icUInt32Number nSize, bool bZeroNew/*=true*/) return true; m_Num = (T*)icRealloc(m_Num, nSize*sizeof(T)); - if (!m_Num) { m_nSize = 0; return false; @@ -6592,6 +6709,8 @@ CIccTagFloatNum::CIccTagFloatNum(int nSize/*=1*/) if (m_nSize <1) m_nSize = 1; m_Num = (T*)calloc(nSize, sizeof(T)); + if (!m_Num) + m_nSize = 0; } @@ -6611,7 +6730,10 @@ CIccTagFloatNum::CIccTagFloatNum(const CIccTagFloatNum &ITNum) m_nSize = ITNum.m_nSize; m_Num = (T*)calloc(m_nSize, sizeof(T)); - memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + if (m_Num) + memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + else + m_nSize = 0; } @@ -6634,7 +6756,10 @@ CIccTagFloatNum &CIccTagFloatNum::operator=(const CIccTagFloat m_nSize = ITNum.m_nSize; m_Num = (T*)calloc(m_nSize, sizeof(T)); - memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + if (m_Num) + memcpy(m_Num, ITNum.m_Num, m_nSize * sizeof(T)); + else + m_nSize = 0; return *this; } @@ -6652,8 +6777,7 @@ CIccTagFloatNum &CIccTagFloatNum::operator=(const CIccTagFloat template CIccTagFloatNum::~CIccTagFloatNum() { - if (m_Num) - free(m_Num); + free(m_Num); } /** @@ -6883,7 +7007,6 @@ bool CIccTagFloatNum::SetSize(icUInt32Number nSize, bool bZeroNew/*=tr return true; m_Num = (T*)icRealloc(m_Num, nSize*sizeof(T)); - if (!m_Num) { m_nSize = 0; return false; @@ -7343,7 +7466,9 @@ icValidateStatus CIccTagMeasurement::Validate(std::string sigPath, std::string & CIccLocalizedUnicode::CIccLocalizedUnicode() { m_pBuf = (icUInt16Number*)malloc(1*sizeof(icUInt16Number)); - *m_pBuf = 0; + if (m_pBuf) + *m_pBuf = 0; + m_nLength = 0; m_nLanguageCode = icLanguageCodeEnglish; m_nCountryCode = icCountryCodeUSA; @@ -7364,10 +7489,15 @@ CIccLocalizedUnicode::CIccLocalizedUnicode(const CIccLocalizedUnicode& ILU) { m_nLength = ILU.GetLength(); m_pBuf = (icUInt16Number*)malloc((m_nLength+2) * sizeof(icUInt16Number)); - if (m_nLength) - memcpy(m_pBuf, ILU.GetBuf(), m_nLength*sizeof(icUInt16Number)); - m_pBuf[m_nLength] = 0; // safety against malformed unicode - m_pBuf[m_nLength+1] = 0; // safety against malformed unicode + if (m_pBuf) { + if (m_nLength) + memcpy(m_pBuf, ILU.GetBuf(), m_nLength*sizeof(icUInt16Number)); + m_pBuf[m_nLength] = 0; // safety against malformed unicode + m_pBuf[m_nLength+1] = 0; // safety against malformed unicode + } + else + m_nLength = 0; + m_nLanguageCode = ILU.m_nLanguageCode; m_nCountryCode = ILU.m_nCountryCode; } @@ -7408,8 +7538,7 @@ CIccLocalizedUnicode &CIccLocalizedUnicode::operator=(const CIccLocalizedUnicode */ CIccLocalizedUnicode::~CIccLocalizedUnicode() { - if (m_pBuf) - free(m_pBuf); + free(m_pBuf); } static bool icIsValidUtf16(const icUInt16Number *pBuf, icUInt32Number nLength) @@ -7590,7 +7719,6 @@ bool CIccLocalizedUnicode::SetSize(icUInt32Number nSize) // Do the size math in 64-bit defensively, even with the cap above. size_t nBytes = (static_cast(nSize) + 2u) * sizeof(icUInt16Number); m_pBuf = (icUInt16Number*)icRealloc(m_pBuf, nBytes); - if (!m_pBuf) { m_nLength = 0; return false; @@ -8324,6 +8452,8 @@ CIccTagData::CIccTagData(int nSize/*=1*/) if (m_nSize <1) m_nSize = 1; m_pData = (icUInt8Number*)calloc(nSize, sizeof(icUInt8Number)); + if (!m_pData) + m_nSize = 0; m_nDataFlag = icAsciiData; } @@ -8344,7 +8474,10 @@ CIccTagData::CIccTagData(const CIccTagData &ITD) m_nSize = ITD.m_nSize; m_pData = (icUInt8Number*)calloc(m_nSize, sizeof(icUInt8Number)); - memcpy(m_pData, ITD.m_pData, sizeof(icUInt8Number)*m_nSize); + if (m_pData) + memcpy(m_pData, ITD.m_pData, sizeof(icUInt8Number)*m_nSize); + else + m_nSize = 0; } @@ -8366,10 +8499,12 @@ CIccTagData &CIccTagData::operator=(const CIccTagData &DataTag) m_nDataFlag = DataTag.m_nDataFlag; m_nSize = DataTag.m_nSize; - if (m_pData) - free(m_pData); + free(m_pData); m_pData = (icUInt8Number*)calloc(m_nSize, sizeof(icUInt8Number)); - memcpy(m_pData, DataTag.m_pData, sizeof(icUInt8Number)*m_nSize); + if (m_pData) + memcpy(m_pData, DataTag.m_pData, sizeof(icUInt8Number)*m_nSize); + else + m_nSize = 0; return *this; } @@ -8385,8 +8520,7 @@ CIccTagData &CIccTagData::operator=(const CIccTagData &DataTag) */ CIccTagData::~CIccTagData() { - if (m_pData) - free(m_pData); + free(m_pData); } @@ -8561,7 +8695,6 @@ bool CIccTagData::SetSize(icUInt32Number nSize, bool bZeroNew/*=true*/) return true; m_pData = (icUInt8Number*)icRealloc(m_pData, nSize*sizeof(icUInt8Number)); - if (!m_pData) { m_nSize = 0; return false; @@ -8848,6 +8981,8 @@ CIccTagColorantOrder::CIccTagColorantOrder(int nsize/*=1*/) if (m_nCount <1) m_nCount = 1; m_pData = (icUInt8Number*)calloc(nsize, sizeof(icUInt8Number)); + if (!m_pData) + m_nCount = 0; } @@ -8867,7 +9002,10 @@ CIccTagColorantOrder::CIccTagColorantOrder(const CIccTagColorantOrder &ITCO) m_nCount = ITCO.m_nCount; m_pData = (icUInt8Number*)calloc(m_nCount, sizeof(icUInt8Number)); - memcpy(m_pData, ITCO.m_pData, sizeof(icUInt8Number)*m_nCount); + if (m_pData) + memcpy(m_pData, ITCO.m_pData, sizeof(icUInt8Number)*m_nCount); + else + m_nCount = 0; } @@ -8888,10 +9026,12 @@ CIccTagColorantOrder &CIccTagColorantOrder::operator=(const CIccTagColorantOrder m_nCount = ColorantOrderTag.m_nCount; - if (m_pData) - free(m_pData); + free(m_pData); m_pData = (icUInt8Number*)calloc(m_nCount, sizeof(icUInt8Number)); - memcpy(m_pData, ColorantOrderTag.m_pData, sizeof(icUInt8Number)*m_nCount); + if (m_pData) + memcpy(m_pData, ColorantOrderTag.m_pData, sizeof(icUInt8Number)*m_nCount); + else + m_nCount = 0; return *this; } @@ -8907,8 +9047,7 @@ CIccTagColorantOrder &CIccTagColorantOrder::operator=(const CIccTagColorantOrder */ CIccTagColorantOrder::~CIccTagColorantOrder() { - if (m_pData) - free(m_pData); + free(m_pData); } @@ -9046,7 +9185,6 @@ bool CIccTagColorantOrder::SetSize(icUInt16Number nSize, bool bZeroNew/*=true*/) return true; m_pData = (icUInt8Number*)icRealloc(m_pData, nSize*sizeof(icUInt8Number)); - if (!m_pData) { m_nCount = 0; return false; @@ -9121,6 +9259,8 @@ CIccTagColorantTable::CIccTagColorantTable(int nSize/*=1*/) m_nCount = 1; m_pData = (icColorantTableEntry*)calloc(nSize, sizeof(icColorantTableEntry)); + if (!m_pData) + m_nCount = 0; } @@ -9140,7 +9280,10 @@ CIccTagColorantTable::CIccTagColorantTable(const CIccTagColorantTable &ITCT) m_nCount = ITCT.m_nCount; m_pData = (icColorantTableEntry*)calloc(m_nCount, sizeof(icColorantTableEntry)); - memcpy(m_pData, ITCT.m_pData, m_nCount*sizeof(icColorantTableEntry)); + if (m_pData) + memcpy(m_pData, ITCT.m_pData, m_nCount*sizeof(icColorantTableEntry)); + else + m_nCount = 0; } @@ -9162,10 +9305,12 @@ CIccTagColorantTable &CIccTagColorantTable::operator=(const CIccTagColorantTable m_PCS = ColorantTableTag.m_PCS; m_nCount = ColorantTableTag.m_nCount; - if (m_pData) - free(m_pData); + free(m_pData); m_pData = (icColorantTableEntry*)calloc(m_nCount, sizeof(icColorantTableEntry)); - memcpy(m_pData, ColorantTableTag.m_pData, m_nCount*sizeof(icColorantTableEntry)); + if (m_pData) + memcpy(m_pData, ColorantTableTag.m_pData, m_nCount*sizeof(icColorantTableEntry)); + else + m_nCount = 0; return *this; } @@ -9181,8 +9326,7 @@ CIccTagColorantTable &CIccTagColorantTable::operator=(const CIccTagColorantTable */ CIccTagColorantTable::~CIccTagColorantTable() { - if (m_pData) - free(m_pData); + free(m_pData); } @@ -9367,7 +9511,6 @@ bool CIccTagColorantTable::SetSize(icUInt16Number nSize, bool bZeroNew/*=true*/) return true; m_pData = (icColorantTableEntry*)icRealloc(m_pData, nSize*sizeof(icColorantTableEntry)); - if (!m_pData) { m_nCount = 0; return false; @@ -10364,7 +10507,8 @@ CIccResponseCurveStruct::CIccResponseCurveStruct(const CIccResponseCurveStruct & m_measurementUnitSig = IRCS.m_measurementUnitSig; m_maxColorantXYZ = (icXYZNumber*)calloc(m_nChannels, sizeof(icXYZNumber)); - memcpy(m_maxColorantXYZ, IRCS.m_maxColorantXYZ, m_nChannels*sizeof(icXYZNumber)); + if (m_maxColorantXYZ) + memcpy(m_maxColorantXYZ, IRCS.m_maxColorantXYZ, m_nChannels*sizeof(icXYZNumber)); m_Response16ListArray = new CIccResponse16List[m_nChannels]; for (icUInt32Number i=0; iVectorMult(rv, m_observer); - range->VectorMult(&rv[newRange.steps], &m_observer[m_observerRange.steps]); - range->VectorMult(&rv[newRange.steps*2], &m_observer[m_observerRange.steps*2]); - delete range; - } - else { - memcpy(rv, m_observer, m_observerRange.steps*3*sizeof(icFloatNumber)); + if (rv) { + CIccMatrixMath *range = CIccMatrixMath::rangeMap(m_observerRange, newRange); + if (range) { + range->VectorMult(rv, m_observer); + range->VectorMult(&rv[newRange.steps], &m_observer[m_observerRange.steps]); + range->VectorMult(&rv[newRange.steps*2], &m_observer[m_observerRange.steps*2]); + delete range; + } + else { + memcpy(rv, m_observer, m_observerRange.steps*3*sizeof(icFloatNumber)); + } } return rv; @@ -12231,6 +12375,8 @@ CIccTagEmbeddedHeightImage::CIccTagEmbeddedHeightImage(int nSize/*=1*/) if (m_nSize <1) m_nSize = 1; m_pData = (icUInt8Number*)calloc(nSize, sizeof(icUInt8Number)); + if (!m_pData) + m_nSize = 0; m_nSeamlesIndicator = 0; m_nEncodingFormat = icPngImageType; m_fMetersMinPixelValue = 0; @@ -12257,7 +12403,10 @@ CIccTagEmbeddedHeightImage::CIccTagEmbeddedHeightImage(const CIccTagEmbeddedHeig m_nSize = IEHI.m_nSize; m_pData = (icUInt8Number*)calloc(m_nSize, sizeof(icUInt8Number)); - memcpy(m_pData, IEHI.m_pData, sizeof(icUInt8Number)*m_nSize); + if (m_pData) + memcpy(m_pData, IEHI.m_pData, sizeof(icUInt8Number)*m_nSize); + else + m_nSize = 0; } @@ -12282,10 +12431,12 @@ CIccTagEmbeddedHeightImage &CIccTagEmbeddedHeightImage::operator=(const CIccTagE m_fMetersMaxPixelValue = HeightImageTag.m_fMetersMaxPixelValue; m_nSize = HeightImageTag.m_nSize; - if (m_pData) - free(m_pData); + free(m_pData); m_pData = (icUInt8Number*)calloc(m_nSize, sizeof(icUInt8Number)); - memcpy(m_pData, HeightImageTag.m_pData, sizeof(icUInt8Number)*m_nSize); + if (m_pData) + memcpy(m_pData, HeightImageTag.m_pData, sizeof(icUInt8Number)*m_nSize); + else + m_nSize = 0; return *this; } @@ -12301,8 +12452,7 @@ CIccTagEmbeddedHeightImage &CIccTagEmbeddedHeightImage::operator=(const CIccTagE */ CIccTagEmbeddedHeightImage::~CIccTagEmbeddedHeightImage() { - if (m_pData) - free(m_pData); + free(m_pData); } @@ -12474,7 +12624,6 @@ bool CIccTagEmbeddedHeightImage::SetSize(icUInt32Number nSize, bool bZeroNew/*=t return true; m_pData = (icUInt8Number*)icRealloc(m_pData, nSize * sizeof(icUInt8Number)); - if (!m_pData) { m_nSize = 0; return false; @@ -12554,6 +12703,8 @@ CIccTagEmbeddedNormalImage::CIccTagEmbeddedNormalImage(int nSize/*=1*/) if (m_nSize < 1) m_nSize = 1; m_pData = (icUInt8Number*)calloc(nSize, sizeof(icUInt8Number)); + if (!m_pData) + m_nSize = 0; m_nSeamlesIndicator = 0; m_nEncodingFormat = icPngImageType; } @@ -12576,7 +12727,10 @@ CIccTagEmbeddedNormalImage::CIccTagEmbeddedNormalImage(const CIccTagEmbeddedNorm m_nSize = IENI.m_nSize; m_pData = (icUInt8Number*)calloc(m_nSize, sizeof(icUInt8Number)); - memcpy(m_pData, IENI.m_pData, sizeof(icUInt8Number)*m_nSize); + if (m_pData) + memcpy(m_pData, IENI.m_pData, sizeof(icUInt8Number)*m_nSize); + else + m_nSize = 0; } @@ -12599,10 +12753,12 @@ CIccTagEmbeddedNormalImage &CIccTagEmbeddedNormalImage::operator=(const CIccTagE m_nEncodingFormat = NormalImageTag.m_nEncodingFormat; m_nSize = NormalImageTag.m_nSize; - if (m_pData) - free(m_pData); + free(m_pData); m_pData = (icUInt8Number*)calloc(m_nSize, sizeof(icUInt8Number)); - memcpy(m_pData, NormalImageTag.m_pData, sizeof(icUInt8Number)*m_nSize); + if (m_pData) + memcpy(m_pData, NormalImageTag.m_pData, sizeof(icUInt8Number)*m_nSize); + else + m_nSize = 0; return *this; } @@ -12618,8 +12774,7 @@ CIccTagEmbeddedNormalImage &CIccTagEmbeddedNormalImage::operator=(const CIccTagE */ CIccTagEmbeddedNormalImage::~CIccTagEmbeddedNormalImage() { - if (m_pData) - free(m_pData); + free(m_pData); } @@ -12774,7 +12929,6 @@ bool CIccTagEmbeddedNormalImage::SetSize(icUInt32Number nSize, bool bZeroNew/*=t return true; m_pData = (icUInt8Number*)icRealloc(m_pData, nSize * sizeof(icUInt8Number)); - if (!m_pData) { m_nSize = 0; return false; diff --git a/IccProfLib/IccTagEmbedIcc.cpp b/IccProfLib/IccTagEmbedIcc.cpp index fec6b2894..3352b5b4e 100644 --- a/IccProfLib/IccTagEmbedIcc.cpp +++ b/IccProfLib/IccTagEmbedIcc.cpp @@ -76,6 +76,7 @@ Copyright: ? see ICC Software License #include #include #include +#include #include "IccTagEmbedIcc.h" #include "IccUtil.h" #include "IccProfile.h" @@ -465,16 +466,24 @@ void CIccTagEmbeddedProfile::Describe(std::string& sDescription, int /* nVerbose // n is number of Tags in Tag Table for (n = 0, i = m_pProfile->m_Tags.begin(); i != m_pProfile->m_Tags.end(); i++, n++) { - // Find closest tag after this tag, by scanning all offsets of other tags + // Find closest tag after this tag, by scanning all offsets of other tags + // NOTE - if this O(N^2) search is a performance problem, copy algorithm from iccDumpProfile closest = pHdr->size; for (j = m_pProfile->m_Tags.begin(); j != m_pProfile->m_Tags.end(); j++) { if ((i != j) && (i->TagInfo.size <= (0xFFFFFFFF - i->TagInfo.offset)) && (j->TagInfo.offset >= i->TagInfo.offset + i->TagInfo.size) && (j->TagInfo.offset <= closest)) { closest = j->TagInfo.offset; } } + // Number of actual padding bytes between this tag and closest neighbour (or EOF) // Should be 0-3 if compliant. Negative number if tags overlap! - pad = closest - i->TagInfo.offset - i->TagInfo.size; + int64_t temp = (int64_t)closest - i->TagInfo.offset - i->TagInfo.size; + if (temp > (int64_t)INT_MAX) + pad = INT_MAX; + else if (temp < (int64_t)INT_MIN) + pad = INT_MIN; + else + pad = (int)temp; const size_t tempSize = 20; char sOffset[tempSize], sSize[tempSize], sPad[tempSize]; diff --git a/IccProfLib/IccTagLut.cpp b/IccProfLib/IccTagLut.cpp index ab98805b7..6eee09328 100644 --- a/IccProfLib/IccTagLut.cpp +++ b/IccProfLib/IccTagLut.cpp @@ -152,8 +152,11 @@ CIccTagCurve::CIccTagCurve(int nSize/*=0*/) m_nMaxIndex = 0; m_Curve = NULL; - if (m_nSize > 0) + if (m_nSize > 0) { m_Curve = (icFloatNumber*)calloc(nSize, sizeof(icFloatNumber)); + if (!m_Curve) + m_nSize = 0; + } } @@ -175,7 +178,10 @@ CIccTagCurve::CIccTagCurve(const CIccTagCurve &ITCurve) if (m_nSize > 0) { m_Curve = (icFloatNumber*)calloc(m_nSize, sizeof(icFloatNumber)); - memcpy(m_Curve, ITCurve.m_Curve, m_nSize*sizeof(icFloatNumber)); + if (m_Curve) + memcpy(m_Curve, ITCurve.m_Curve, m_nSize*sizeof(icFloatNumber)); + else + m_nSize = 0; } } @@ -198,13 +204,15 @@ CIccTagCurve &CIccTagCurve::operator=(const CIccTagCurve &CurveTag) m_nSize = CurveTag.m_nSize; m_nMaxIndex = CurveTag.m_nMaxIndex; - if (m_Curve) - free(m_Curve); + free(m_Curve); m_Curve = NULL; if (m_nSize > 0) { m_Curve = (icFloatNumber*)calloc(m_nSize, sizeof(icFloatNumber)); - memcpy(m_Curve, CurveTag.m_Curve, m_nSize*sizeof(icFloatNumber)); + if (m_Curve) + memcpy(m_Curve, CurveTag.m_Curve, m_nSize*sizeof(icFloatNumber)); + else + m_nSize = 0; } return *this; @@ -221,8 +229,7 @@ CIccTagCurve &CIccTagCurve::operator=(const CIccTagCurve &CurveTag) */ CIccTagCurve::~CIccTagCurve() { - if (m_Curve) - free(m_Curve); + free(m_Curve); } @@ -421,7 +428,7 @@ void CIccTagCurve::DumpLut(std::string &sDescription, const icChar *szName, for (i=0; i<(int)m_nSize; i++) { ptr = buf; - icFloatNumber fraction = (m_nSize > 1) ? ((icFloatNumber)i/(m_nSize-1)) : 1.0f; + icFloatNumber fraction = (icFloatNumber)i/(m_nSize-1); icColorValue(buf, bufSize, fraction, csSig, nIndex); ptr += strlen(buf); @@ -458,11 +465,10 @@ bool CIccTagCurve::SetSize(icUInt32Number nSize, icTagCurveSizeInit nSizeOpt/*=i if (nSize==m_nSize) return true; - if (!nSize) { - if (m_Curve) { - free(m_Curve); - m_Curve = NULL; - } + // set upper limit of 65536 table entries, to help catch errors + if (!nSize || nSize > 65536) { + free(m_Curve); + m_Curve = NULL; m_nSize = 0; return true; } @@ -1691,14 +1697,10 @@ CIccApplyCLUT::CIccApplyCLUT() */ CIccApplyCLUT::~CIccApplyCLUT() { - if (m_df) - free(m_df); - if (m_s) - free(m_s); - if (m_g) - free(m_g); - if (m_ig) - free(m_ig); + free(m_df); + free(m_s); + free(m_g); + free(m_ig); } @@ -5461,7 +5463,7 @@ bool CIccTagLut16::Read(icUInt32Number size, CIccIO *pIO) if (!pCurve->SetSize(nInputEntries)) return false; - if ((nInputEntries > 0) && pIO->ReadUInt16Float(&(*pCurve)[0], nInputEntries) != nInputEntries) + if (pIO->ReadUInt16Float(&(*pCurve)[0], nInputEntries) != nInputEntries) return false; } @@ -5493,7 +5495,7 @@ bool CIccTagLut16::Read(icUInt32Number size, CIccIO *pIO) if (!pCurve->SetSize(nOutputEntries)) return false; - if ((nOutputEntries > 0) && pIO->ReadUInt16Float(&(*pCurve)[0], nOutputEntries) != nOutputEntries) + if (pIO->ReadUInt16Float(&(*pCurve)[0], nOutputEntries) != nOutputEntries) return false; } return true; @@ -6022,7 +6024,13 @@ bool CIccTagGamutBoundaryDesc::Read(icUInt32Number size, CIccIO *pIO) delete [] m_Triangles; size_t pcsSize = (size_t)m_nPCSChannels * (size_t)m_NumberOfVertices; + if (pcsSize > (size_t)UINT32_MAX) + return false; + size_t deviceSize = (size_t)m_nDeviceChannels * (size_t)m_NumberOfVertices; + if (deviceSize > (size_t)UINT32_MAX) + return false; + m_PCSValues = new (std::nothrow) icFloatNumber[pcsSize]; if (!m_PCSValues) @@ -6052,9 +6060,6 @@ bool CIccTagGamutBoundaryDesc::Read(icUInt32Number size, CIccIO *pIO) if (pIO->Read32(m_Triangles, nNum32)!=nNum32) return false; - if (pcsSize > (size_t)UINT32_MAX) - return false; - nNum32 = (icUInt32Number) pcsSize; if (pIO->ReadFloat32Float(m_PCSValues, nNum32)!=nNum32) @@ -6062,11 +6067,8 @@ bool CIccTagGamutBoundaryDesc::Read(icUInt32Number size, CIccIO *pIO) if (m_nDeviceChannels > 0) { - if (pcsSize > (size_t)UINT32_MAX) - return false; - nNum32 = (icUInt32Number) deviceSize; - + if (pIO->ReadFloat32Float(m_DeviceValues, nNum32)!=nNum32) return false; } diff --git a/IccProfLib/IccTagMPE.cpp b/IccProfLib/IccTagMPE.cpp index 0badf2a40..85d50c35f 100644 --- a/IccProfLib/IccTagMPE.cpp +++ b/IccProfLib/IccTagMPE.cpp @@ -208,23 +208,22 @@ CIccMpeUnknown::CIccMpeUnknown(const CIccMpeUnknown &elem) ******************************************************************************/ CIccMpeUnknown &CIccMpeUnknown::operator=(const CIccMpeUnknown &elem) { - if (m_pData) - free(m_pData); + free(m_pData); - m_sig = elem.m_sig; - m_nReserved = elem.m_nReserved; - m_nInputChannels = elem.m_nInputChannels; - m_nOutputChannels = elem.m_nOutputChannels; - m_nSize = elem.m_nSize; - if (m_nSize) { - m_pData = (icUInt8Number*)malloc(m_nSize); - if (m_pData) + m_sig = elem.m_sig; + m_nReserved = elem.m_nReserved; + m_nInputChannels = elem.m_nInputChannels; + m_nOutputChannels = elem.m_nOutputChannels; + m_nSize = elem.m_nSize; + if (m_nSize) { + m_pData = (icUInt8Number*)malloc(m_nSize); + if (m_pData) memcpy(m_pData, elem.m_pData, m_nSize); - } - else - m_pData = NULL; + } + else + m_pData = NULL; - return (*this); + return (*this); } /** @@ -239,8 +238,7 @@ CIccMpeUnknown &CIccMpeUnknown::operator=(const CIccMpeUnknown &elem) ******************************************************************************/ CIccMpeUnknown::~CIccMpeUnknown() { - if (m_pData) - free(m_pData); + free(m_pData); } /** @@ -313,8 +311,7 @@ void CIccMpeUnknown::Describe(std::string &sDescription, int nVerboseness) bool CIccMpeUnknown::SetDataSize(icUInt32Number nSize, bool /* bZeroData =true */) { bool rv = true; - if (m_pData) - free(m_pData); + free(m_pData); // Prevent excessive allocation - limit to 256MB for unknown MPE data const icUInt32Number MAX_MPE_UNKNOWN_SIZE = 268435456; // 256 MB @@ -588,14 +585,12 @@ CIccDblPixelBuffer::~CIccDblPixelBuffer() ******************************************************************************/ void CIccDblPixelBuffer::Clean() { - if (m_pixelBuf1) { - free(m_pixelBuf1); - m_pixelBuf1 = NULL; - } - if (m_pixelBuf2) { - free(m_pixelBuf2); - m_pixelBuf2 = NULL; - } + free(m_pixelBuf1); + m_pixelBuf1 = NULL; + + free(m_pixelBuf2); + m_pixelBuf2 = NULL; + m_nMaxChannels = 0; m_nLastNumChannels = 0; } @@ -858,10 +853,8 @@ void CIccTagMultiProcessElement::Clean() m_list = NULL; } - if (m_position) { - free(m_position); - m_position = NULL; - } + free(m_position); + m_position = NULL; m_nProcElements = 0; } @@ -1131,10 +1124,7 @@ bool CIccTagMultiProcessElement::Write(CIccIO *pIO) if (m_nProcElements) { size_t offsetPos = pIO->Tell(); - if (m_position) { - free(m_position); - } - + free(m_position); m_position = (icPositionNumber*)calloc(m_nProcElements, sizeof(icPositionNumber)); if (!m_position) diff --git a/IccProfLib/IccUtil.cpp b/IccProfLib/IccUtil.cpp index bf179d446..94d68aa47 100644 --- a/IccProfLib/IccUtil.cpp +++ b/IccProfLib/IccUtil.cpp @@ -124,7 +124,7 @@ ICCPROFLIB_API const char* icMsgValidateInformation = "Information - "; else nptr = malloc(size); - if (!nptr && ptr) + if (!nptr) free(ptr); return nptr; diff --git a/IccXML/IccLibXML/IccMpeXml.cpp b/IccXML/IccLibXML/IccMpeXml.cpp index 9a9f43907..a4adefbae 100644 --- a/IccXML/IccLibXML/IccMpeXml.cpp +++ b/IccXML/IccLibXML/IccMpeXml.cpp @@ -306,9 +306,7 @@ bool CIccFormulaCurveSegmentXml::ParseXml(xmlNode *pNode, std::string &parseStr) if (args.GetSize()GetNameLocalized(); if (!pTag) { pTag = new (std::nothrow) CIccTagMultiLocalizedUnicode(); - if (!pTag) + if (!pTag) { + delete pDesc; + ptr.ptr = NULL; return false; + } pDesc->SetNameLocalized(pTag); } @@ -4578,8 +4589,11 @@ bool CIccTagXmlDict::ParseXml(xmlNode *pNode, std::string & /*parseStr*/) CIccTagMultiLocalizedUnicode *pTag = pDesc->GetValueLocalized(); if (!pTag) { pTag = new (std::nothrow) CIccTagMultiLocalizedUnicode(); - if (!pTag) + if (!pTag) { + delete pDesc; + ptr.ptr = NULL; return false; + } pDesc->SetValueLocalized(pTag); } diff --git a/IccXML/IccLibXML/IccUtilXml.cpp b/IccXML/IccLibXML/IccUtilXml.cpp index 75a838741..4771ed314 100644 --- a/IccXML/IccLibXML/IccUtilXml.cpp +++ b/IccXML/IccLibXML/IccUtilXml.cpp @@ -565,9 +565,7 @@ CIccXmlArrayType::CIccXmlArrayType() template CIccXmlArrayType::~CIccXmlArrayType() { - if (m_pBuf) { - free(m_pBuf); - } + free(m_pBuf); } template @@ -973,9 +971,7 @@ bool CIccXmlArrayType::ParseArray(T* pBuf, icUInt32Number nSize, xmlNod template bool CIccXmlArrayType::SetSize(icUInt32Number nSize) { - if (m_pBuf) { - free(m_pBuf); - } + free(m_pBuf); m_pBuf = (T*)malloc(nSize * sizeof(T)); if (!m_pBuf) { m_nSize = 0; diff --git a/Testing/Named/NamedColorV4_luts.pdf b/Testing/Named/NamedColorV4_luts.pdf new file mode 100644 index 000000000..5b30a9534 Binary files /dev/null and b/Testing/Named/NamedColorV4_luts.pdf differ diff --git a/Tools/CmdLine/IccApplySearch/iccApplySearch.cpp b/Tools/CmdLine/IccApplySearch/iccApplySearch.cpp index 6012bb99f..fd7851f86 100644 --- a/Tools/CmdLine/IccApplySearch/iccApplySearch.cpp +++ b/Tools/CmdLine/IccApplySearch/iccApplySearch.cpp @@ -267,7 +267,7 @@ int main(int argc, const char* argv[]) CIccCfgSearchApply cfgSearchApply; CIccCfgColorData cfgData; - if (argc > 2 && !stricmp(argv[1], "-cfg")) { + if (!stricmp(argv[1], "-cfg")) { json cfg; if (!loadJsonFrom(cfg, argv[2]) || !cfg.is_object()) { printf("Unable to read configuration from '%s'\n", argv[2]); diff --git a/Tools/CmdLine/IccPawgReport/IccQualityMetrics.h b/Tools/CmdLine/IccPawgReport/IccQualityMetrics.h index 8385d93b2..072272d0d 100644 --- a/Tools/CmdLine/IccPawgReport/IccQualityMetrics.h +++ b/Tools/CmdLine/IccPawgReport/IccQualityMetrics.h @@ -1430,9 +1430,10 @@ inline void append_mbb_curve_targets(std::vectorIsInputMatrix() ? mbb->InputChannels() : mbb->OutputChannels(); const int bCurves = mbb->IsInputB() ? mbb->InputChannels() : mbb->OutputChannels(); - if (aCurves < 0 || aCurves > kMaxQualityChannels || - mCurves < 0 || mCurves > kMaxQualityChannels || - bCurves < 0 || bCurves > kMaxQualityChannels) { + // they can't be negative when copied from unsigned values + if (aCurves > kMaxQualityChannels || + mCurves > kMaxQualityChannels || + bCurves > kMaxQualityChannels) { return; } diff --git a/Tools/CmdLine/IccRoundTrip/iccRoundTrip.cpp b/Tools/CmdLine/IccRoundTrip/iccRoundTrip.cpp index 7c3205e59..e986e3599 100644 --- a/Tools/CmdLine/IccRoundTrip/iccRoundTrip.cpp +++ b/Tools/CmdLine/IccRoundTrip/iccRoundTrip.cpp @@ -83,14 +83,8 @@ class CIccMinMaxEval : public CIccEvalCompare void Compare(icFloatNumber *pixel, icFloatNumber *deviceLab, icFloatNumber *lab1, icFloatNumber *lab2); - icFloatNumber GetMean1() { if (fabs(num1) < 1e-8) - return 0.0; - else - return sum1 / num1; } - icFloatNumber GetMean2() { if (fabs(num2) < 1e-8) - return 0.0; - else - return sum2 / num2; } + icFloatNumber GetMean1() { if (num1 == 0.0) return 0.0; return sum1 / num1; } + icFloatNumber GetMean2() { if (num2 == 0.0) return 0.0; else return sum2 / num2; } icFloatNumber minDE1, minDE2; icFloatNumber maxDE1, maxDE2; diff --git a/Tools/wxWidget/wxProfileDump/wxProfileDump.cpp b/Tools/wxWidget/wxProfileDump/wxProfileDump.cpp index edf87c4ac..46ce280ac 100644 --- a/Tools/wxWidget/wxProfileDump/wxProfileDump.cpp +++ b/Tools/wxWidget/wxProfileDump/wxProfileDump.cpp @@ -949,8 +949,8 @@ class CIccMinMaxEval : public CIccEvalCompare void Compare(icFloatNumber *pixel, icFloatNumber *deviceLab, icFloatNumber *lab1, icFloatNumber *lab2); - icFloatNumber GetMean1() { return sum1 / num1; } - icFloatNumber GetMean2() { return sum2 / num2; } + icFloatNumber GetMean1() { if (num1 == 0.0) return 0.0; else return sum1 / num1; } + icFloatNumber GetMean2() { if (num2 == 0.0) return 0.0; else return sum2 / num2; } icFloatNumber minDE1, minDE2; icFloatNumber maxDE1, maxDE2; @@ -1064,7 +1064,10 @@ wxString AnalyzeRoundTrip(wxString &profilePath, icRenderingIntent nIntent, bool report += wxString::Format(" Min DeltaE: %8.2" ICFLOATSFX "\n", eval.minDE2); report += wxString::Format(" Mean DeltaE: %8.2" ICFLOATSFX "\n", eval.GetMean2()); report += wxString::Format(" Max DeltaE: %8.2" ICFLOATSFX "\n", eval.maxDE2); - report += wxString::Format(" DE <= 1.0 (%8u): %5.1f%%\n\n", eval.num3, (float)eval.num3 / (float)eval.m_nTotal*100.0); + float scaleEval = 0.0f; + if (eval.m_nTotal > 0) + scaleEval = 100.0f / (float)eval.m_nTotal; + report += wxString::Format(" DE <= 1.0 (%8u): %5.1f%%\n\n", eval.num3, scaleEval*(float)eval.num3); report += wxString::Format(" Max L, a, b: " ICFLOATFMT ", " ICFLOATFMT ", " ICFLOATFMT "\n", eval.maxLab2[0], eval.maxLab2[1], eval.maxLab2[2]); @@ -1072,11 +1075,12 @@ wxString AnalyzeRoundTrip(wxString &profilePath, icRenderingIntent nIntent, bool report += wxString::Format("\n PRMG Interoperability - Round Trip Results\n"); report += wxString::Format( " ------------------------------------------------------\n"); - report += wxString::Format(" DE <= 1.0 (%8u): %5.1f%%\n", prmg.m_nDE1, (float)prmg.m_nDE1/(float)prmg.m_nTotal*100.0); - report += wxString::Format(" DE <= 2.0 (%8u): %5.1f%%\n", prmg.m_nDE2, (float)prmg.m_nDE2/(float)prmg.m_nTotal*100.0); - report += wxString::Format(" DE <= 3.0 (%8u): %5.1f%%\n", prmg.m_nDE3, (float)prmg.m_nDE3/(float)prmg.m_nTotal*100.0); - report += wxString::Format(" DE <= 5.0 (%8u): %5.1f%%\n", prmg.m_nDE5, (float)prmg.m_nDE5/(float)prmg.m_nTotal*100.0); - report += wxString::Format(" DE <=10.0 (%8u): %5.1f%%\n", prmg.m_nDE10, (float)prmg.m_nDE10/(float)prmg.m_nTotal*100.0); + float scaling = 100.0f / (float)prmg.m_nTotal; + report += wxString::Format(" DE <= 1.0 (%8u): %5.1f%%\n", prmg.m_nDE1, scaling*(float)prmg.m_nDE1); + report += wxString::Format(" DE <= 2.0 (%8u): %5.1f%%\n", prmg.m_nDE2, scaling*(float)prmg.m_nDE2); + report += wxString::Format(" DE <= 3.0 (%8u): %5.1f%%\n", prmg.m_nDE3, scaling*(float)prmg.m_nDE3); + report += wxString::Format(" DE <= 5.0 (%8u): %5.1f%%\n", prmg.m_nDE5, scaling*(float)prmg.m_nDE5); + report += wxString::Format(" DE <=10.0 (%8u): %5.1f%%\n", prmg.m_nDE10, scaling*(float)prmg.m_nDE10); report += wxString::Format(" Total (%8u)\n", prmg.m_nTotal); }