Tk Source Code

View Ticket
Login
Ticket UUID: 3134d697c8a23ad68a0beeedf787c021bb64241b
Title: Reduce unnecessary code checks
Type: Patch Version: trunk
Submitter: emiliano Created on: 2020-03-22 15:24:38
Subsystem: 06. Canvas Postscript Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-04-04 19:25:53
Resolution: Fixed Closed By: fvogel
    Closed on: 2020-04-04 19:25:53
Description:
Postcript generation code is littered with code like this

if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
    goto error;
}

Checking the code, is evident that some of the supporting functions in
postscript generation cannot fail, so checks are redundant.

Those supporting functions are

Tk_CanvasPsColor
Tk_CanvasPsStipple
Tk_CanvasPsBitmap

all defined in generic/tkCanvas.c, they just forward to the functions

Tk_PostscriptColor
Tk_PostscriptStipple
Tk_PostscriptBimap

in the file generic/tkCanvPs.c, all of which unconditionally return TCL_OK.

Other supporting functions

Tk_CanvasPsOutline
ArrowheadPostscript

are checked against errors but the only code path in which such errors could
arise is from the use of the three functions mentioned above, so they couldn't
fail either.

Attached patch removes unnecessary code checks.
User Comments: fvogel added on 2020-04-04 19:25:53:
Merged to trunk.

fvogel added on 2020-03-29 17:40:37:

Many thanks for this analysis and patch. I have committed the latter in a bugfix branch, see [0e035f0e].

Your analysis looks totally correct to me.


emiliano added on 2020-03-22 15:29:19:
Is also worth noting that generic/tkCanTxt.c, line 1644 already has an unchecked call to Tk_CanvasPsStipple

Attachments: