summaryrefslogtreecommitdiff
path: root/base/gsparam.c
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2019-10-25 13:52:44 +0100
committerChris Liddell <chris.liddell@artifex.com>2019-10-25 15:43:18 +0100
commit17ad4a12dd40799655b71a93de1209a6a0f24204 (patch)
tree358e94bb928d817d6334fc7164410ff23c19b7f5 /base/gsparam.c
parent62a1c3cdbb374d2f90b00f7aa276be50961c580a (diff)
downloadghostpdl-17ad4a12dd40799655b71a93de1209a6a0f24204.tar.gz
Coverity issues: Assignment of overlapping union members
Strictly speaking assigning one element of union to another, overlapping element of a different size is undefined behavior, hence assign to intermediate variables before setting the other element in the union. Coverity #: 350159, 350173, 350205, 350176, 350215, 350192
Diffstat (limited to 'base/gsparam.c')
-rw-r--r--base/gsparam.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/base/gsparam.c b/base/gsparam.c
index b235d8601..80cb0b2aa 100644
--- a/base/gsparam.c
+++ b/base/gsparam.c
@@ -171,15 +171,25 @@ param_coerce_typed(gs_param_typed_value * pvalue, gs_param_type req_type,
* right now we can't. However, a 0-length heterogenous array
* will satisfy a request for any specific type.
*/
+ /* Strictly speaking assigning one element of union
+ * to another, overlapping element of a different size is
+ * undefined behavior, hence assign to intermediate variables
+ */
switch (pvalue->type /* actual type */ ) {
case gs_param_type_int:
switch (req_type) {
case gs_param_type_long:
- pvalue->value.l = pvalue->value.i;
+ {
+ long l = (long)pvalue->value.i;
+ pvalue->value.l = l;
goto ok;
+ }
case gs_param_type_float:
- pvalue->value.f = (float)pvalue->value.l;
+ {
+ float fl = (float)pvalue->value.l;
+ pvalue->value.f = fl;
goto ok;
+ }
default:
break;
}
@@ -187,15 +197,22 @@ param_coerce_typed(gs_param_typed_value * pvalue, gs_param_type req_type,
case gs_param_type_long:
switch (req_type) {
case gs_param_type_int:
+ {
+ int int1;
#if ARCH_SIZEOF_INT < ARCH_SIZEOF_LONG
if (pvalue->value.l != (int)pvalue->value.l)
return_error(gs_error_rangecheck);
#endif
- pvalue->value.i = (int)pvalue->value.l;
+ int1 = (int)pvalue->value.l;
+ pvalue->value.i = int1;
goto ok;
+ }
case gs_param_type_float:
- pvalue->value.f = (float)pvalue->value.l;
+ {
+ float fl = (float)pvalue->value.l;
+ pvalue->value.f = fl;
goto ok;
+ }
default:
break;
}