Overview
Artifact ID: | b00eb3e745daa91b27a5d5746efcf32b619ac3b89051a5526d2f57427d94f677 |
---|---|
Ticket: | 1e48483c8b3b2702b981ebcc85474512bb3d6e0d
Use of non-standard C code in TCLBOOLWARNING |
User & Date: | gustafn3 2024-04-26 09:51:04 |
Changes
- icomment:
As i read this, the intention is to issue an error, when someone passes in a value larger than "int" as result pointer in Tcl_GetBooleanFromObj(interp, objv[0], boolPtr); since there is later a cast Tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) For the code { size_t large = 0; result = Tcl_GetBooleanFromObj(interp, objPtr, &large); } the error message in this case will be error: '_bool_Var' declared as an array with a negative size as also the comment documents. This is not great for the following reasons: 1) strange error message 2) generated only on GNU compatible compilers 3) handles just a particular case (object for the result is too large, why not covering too small?) 4) raises a warning also in cases, where everything is fine (when the paranoia flags are turned on, probably many developers will do this, when moving to tcl9) Why not using static_assert( constant-expression, string-literal ) when available. It is part of - C11 - MS: VS 2015 - GCC since gcc-4.6 With some mental contortion, one can also sneak it into expressions, as the following snippet shows. { size_t large = 0; result = Tcl_GetBooleanFromObj(interp, objPtr, &large) + (int)(sizeof(struct {static_assert(sizeof(large) <= sizeof(int),"all is lost");int dummy;})*0) ; } This would address (1) and (4) and improves the situation on (2) as well.
- login: "gustafn3"
- mimetype: "text/plain"