Skip to content

Commit

Permalink
Some housekeeping
Browse files Browse the repository at this point in the history
Clean resources on error
Guard against null dereferences
  • Loading branch information
mm2 committed Nov 8, 2023
1 parent fef7796 commit 6491e2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/cmsps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsUInt32Number Intent
cmsUInt32Number InFrm = TYPE_Lab_16;
cmsUInt32Number RelativeEncodingIntent;
cmsColorSpaceSignature ColorSpace;

cmsStage* first;

hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL);
if (hLab == NULL) return 0;
Expand Down Expand Up @@ -1295,17 +1295,20 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsUInt32Number Intent

if (xform == NULL) {

cmsDeleteTransform(xform);
cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Lab -> Profile in CRD creation");
return 0;
}

// Get a copy of the internal devicelink
v = (_cmsTRANSFORM*) xform;
DeviceLink = cmsPipelineDup(v ->Lut);
if (DeviceLink == NULL) return 0;

if (DeviceLink == NULL) {
cmsDeleteTransform(xform);
return 0;
}

// We need a CLUT
// We need a CLUT
dwFlags |= cmsFLAGS_FORCE_CLUT;
_cmsOptimizePipeline(m->ContextID, &DeviceLink, RelativeEncodingIntent, &InFrm, &OutputFormat, &dwFlags);

Expand All @@ -1332,8 +1335,10 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsUInt32Number Intent

_cmsIOPrintf(m, "/RenderTable ");


WriteCLUT(m, cmsPipelineGetPtrToFirstStage(DeviceLink), "<", ">\n", "", "", lFixWhite, ColorSpace);
first = cmsPipelineGetPtrToFirstStage(DeviceLink);
if (first != NULL) {
WriteCLUT(m, first, "<", ">\n", "", "", lFixWhite, ColorSpace);
}

_cmsIOPrintf(m, " %d {} bind ", nChannels);

Expand All @@ -1342,7 +1347,6 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsUInt32Number Intent

_cmsIOPrintf(m, "]\n");


EmitIntent(m, Intent);

_cmsIOPrintf(m, ">>\n");
Expand Down
7 changes: 3 additions & 4 deletions src/cmsvirt.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,9 @@ cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext ContextID,

if (Limit < 0.0 || Limit > 400) {

cmsSignalError(ContextID, cmsERROR_RANGE, "InkLimiting: Limit should be between 0..400");
if (Limit < 0) Limit = 0;
cmsSignalError(ContextID, cmsERROR_RANGE, "InkLimiting: Limit should be between 1..400");
if (Limit < 1) Limit = 1;
if (Limit > 400) Limit = 400;

}

hICC = cmsCreateProfilePlaceholder(ContextID);
Expand Down Expand Up @@ -1152,7 +1151,7 @@ cmsBool CheckOne(const cmsAllowedLUT* Tab, const cmsPipeline* Lut)

for (n=0, mpe = Lut ->Elements; mpe != NULL; mpe = mpe ->Next, n++) {

if (n > Tab ->nTypes) return FALSE;
if (n >= Tab ->nTypes) return FALSE;
if (cmsStageType(mpe) != Tab ->MpeTypes[n]) return FALSE;
}

Expand Down

0 comments on commit 6491e2e

Please sign in to comment.