summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2024-03-03 18:51:46 -0500
committerThomas E. Dickey <dickey@invisible-island.net>2024-03-04 03:53:29 -0500
commitfd4b2ce63feae01744a850fa6f1809ff15361a8b (patch)
tree1b3c1e374bcc7a70e621a3327e6eb8d37bd55521
parentd33708e30f102f6ab278d6f809eeaa18e65d0716 (diff)
fix clang/gcc warnings for undefined behavior, also fix a bug
XtConvertAndStore may update the XrmValue value, changing its size. clang and gcc warn about undefined behavior in the case-statement following the call (which uses the size), but do not explain what the problem is. Since this code is not intended to handle changes of the size, simply reject that case. That quiets the gcc warnings and is actually all that is needed for correctness. clang still complains (neither knows what the call does), but can be quieted by initializing the variable before calling the function. The code happens to work without the fix as long as it is not used to convert between resource types which would increase the size. Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
-rw-r--r--src/Actions.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Actions.c b/src/Actions.c
index 8f0cead..abb61ef 100644
--- a/src/Actions.c
+++ b/src/Actions.c
@@ -413,6 +413,7 @@ XawSetValuesAction(Widget w, XEvent *event,
#ifdef LONG64
long c_8;
#endif
+ unsigned use_size;
if (!(*num_params & 1))
{
@@ -444,13 +445,14 @@ XawSetValuesAction(Widget w, XEvent *event,
from.size = (Cardinal) strlen(value) + 1;
from.addr = (char *)value;
to.size = resource->size;
- switch (to.size)
+ use_size = resource->size;
+ switch (use_size)
{
- case 1: to.addr = (XPointer)&c_1; break;
- case 2: to.addr = (XPointer)&c_2; break;
- case 4: to.addr = (XPointer)&c_4; break;
+ case 1: to.addr = (XPointer)&c_1; c_1 = 0; break;
+ case 2: to.addr = (XPointer)&c_2; c_2 = 0; break;
+ case 4: to.addr = (XPointer)&c_4; c_4 = 0; break;
#ifdef LONG64
- case 8: to.addr = (XPointer)&c_8; break;
+ case 8: to.addr = (XPointer)&c_8; c_8 = 0; break;
#endif
default:
{
@@ -470,10 +472,11 @@ XawSetValuesAction(Widget w, XEvent *event,
c_4 = (int)from.addr;
#endif
else if (!XtConvertAndStore(w, XtRString, &from,
- XrmQuarkToString(resource->qtype), &to))
+ XrmQuarkToString(resource->qtype), &to)
+ || to.size != use_size)
continue;
- switch (to.size)
+ switch (use_size)
{
case 1:
XtSetArg(arglist[num_args], XrmQuarkToString(resource->qname), c_1);