Tk Source Code

View Ticket
Login
2022-08-20
13:34 Closed ticket [71b1e5e331]: xgc.c: useless NULL check in XCreateGC() plus 5 other changes artifact: 2edf91b74f user: fvogel
13:32
Fix [71b1e5e331]: xgc.c: useless NULL check in XCreateGC(). Thanks to Christopher Chavez. check-in: 25aa643b09 user: fvogel tags: trunk, main
13:32
Fix [71b1e5e331]: xgc.c: useless NULL check in XCreateGC(). Thanks to Christopher Chavez. check-in: 4bb27fb595 user: fvogel tags: core-8-6-branch
13:19
Fix [71b1e5e331]: xgc.c: useless NULL check in XCreateGC(). Thanks to Christopher Chavez. Closed-Leaf check-in: 9096fd4d70 user: fvogel tags: mistake
2022-08-19
20:06 Ticket [71b1e5e331] xgc.c: useless NULL check in XCreateGC() status still Open with 5 other changes artifact: cead838591 user: fvogel
20:06
Fix [71b1e5e331]: xgc.c: useless NULL check in XCreateGC(). Thanks to Christopher Chavez. Closed-Leaf check-in: 8656d3f4cd user: fvogel tags: bug-71b1e5e331
2022-08-14
11:05 New ticket [71b1e5e331] xgc.c: useless NULL check in XCreateGC(). artifact: 5fd15d9595 user: chrstphrchvz

Ticket UUID: 71b1e5e3318be7caac7c8960e82100f0fc749d86
Title: xgc.c: useless NULL check in XCreateGC()
Type: Patch Version: 8.6.12
Submitter: chrstphrchvz Created on: 2022-08-14 11:05:45
Subsystem: 82. X11 Emulation Assigned To: fvogel
Priority: 5 Medium Severity: Cosmetic
Status: Closed Last Modified: 2022-08-20 13:34:51
Resolution: Fixed Closed By: fvogel
    Closed on: 2022-08-20 13:34:51
Description:
In `XCreateGC()`:

```
    gp = (GC)ckalloc(sizeof(XGCValuesWithDash));
    if (!gp) {
	return NULL;
    }
```

`ckalloc()` never returns `NULL` when given nonzero size (it will instead panic if allocation fails), and I don’t think there is any situation here where `ckalloc()` is given size of 0. So `return NULL` is unreachable. I suggest removing it, unless the intention was to use `attemptckalloc()`.
User Comments: fvogel added on 2022-08-20 13:34:51:
Continuous integration (Github Actions) is happy, therefore now merged in core-8-6-branch and trunk. Thanks!

fvogel added on 2022-08-19 20:06:44:

I understand your point. XGCValuesWithDash is defined in xgc.c and has non-zero size. We don't check for NULL return values of ckalloc() in similar situations elsewhere in the code I think, for the reason you mention.

I have committed your patch in [8656d3f4cd].