Closed Bug 46087 Opened 24 years ago Closed 24 years ago

improper use of va_arg to access non-promoted types

Categories

(Core Graveyard :: Java: OJI, defect, P3)

All
Linux
defect

Tracking

(Not tracked)

VERIFIED DUPLICATE of bug 39050

People

(Reporter: khendricks, Assigned: drapeau)

Details

ansi standard used by gcc says it is illegal to access a non-promoted type via
va_arg().  The correct solution is to access it via the promoted type and then
cast it to the subtype.

For example:  short_var = va_arg(arglist,short) is wrong and will return an
error using the latest gcc CVS tree.

It should be written as follows:

short_var = (short)va_arg(arglist,int)

I have enclosed a patch that fixes problems of this type in the modules/oji
tree.  These fixes are required for the JDK plugin to work when mozilla is built
with gcc cvs tree version or with linux ppc currently.

Here is the patch.  If you need more info about this patch please post to the
gcc mialing list directly or contact me.

--- modules/oji/src/nsJNI.cpp.prev      Thu Jul 20 11:33:12 2000
+++ modules/oji/src/nsJNI.cpp   Thu Jul 20 11:34:49 2000
@@ -178,16 +178,16 @@
                                jargs[i].l = va_arg(args, jobject);
                                break;
                        case jboolean_type:
-                               jargs[i].z = va_arg(args, jboolean);
+                               jargs[i].z = (jboolean)va_arg(args, jint);
                                break;
                        case jbyte_type:
-                               jargs[i].b = va_arg(args, jbyte);
+                               jargs[i].b = (jbyte)va_arg(args, jint);
                                break;
                        case jchar_type:
-                               jargs[i].b = va_arg(args, jbyte);
+                               jargs[i].b = (jbyte)va_arg(args, jint);
                                break;
                        case jshort_type:
-                               jargs[i].s = va_arg(args, jshort);
+                               jargs[i].s = (jshort)va_arg(args, jint);
                                break;
                        case jint_type:
                                jargs[i].i = va_arg(args, jint);
@@ -196,7 +196,7 @@
                                jargs[i].j = va_arg(args, jlong);
                                break;
                        case jfloat_type:
-                               jargs[i].f = va_arg(args, jfloat);
+                               jargs[i].f = (jfloat)va_arg(args, jdouble);
                                break;
                        case jdouble_type:
                                jargs[i].d = va_arg(args, jdouble);
--- modules/oji/src/ProxyJNI.cpp.prev   Thu Jul 20 11:33:28 2000
+++ modules/oji/src/ProxyJNI.cpp        Thu Jul 20 11:36:26 2000
@@ -183,16 +183,16 @@
                                        jargs[i].l = va_arg(args, jobject);
                                        break;
                                case jboolean_type:
-                                       jargs[i].z = va_arg(args, jboolean);
+                                       jargs[i].z = (jboolean)va_arg(args,
jint);
                                        break;
                                case jbyte_type:
-                                       jargs[i].b = va_arg(args, jbyte);
+                                       jargs[i].b = (jbyte)va_arg(args, jint);
                                        break;
                                case jchar_type:
-                                       jargs[i].b = va_arg(args, jbyte);
+                                       jargs[i].b = (jbyte)va_arg(args, jint);
                                        break;
                                case jshort_type:
-                                       jargs[i].s = va_arg(args, jshort);
+                                       jargs[i].s = (jshort)va_arg(args, jint);
                                        break;
                                case jint_type:
                                        jargs[i].i = va_arg(args, jint);
@@ -201,7 +201,7 @@
                                        jargs[i].j = va_arg(args, jlong);
                                        break;
                                case jfloat_type:
-                                       jargs[i].f = va_arg(args, jfloat);
+                                       jargs[i].f = (jfloat)va_arg(args,
jdouble);
                                        break;
                                case jdouble_type:
                                        jargs[i].d = va_arg(args, jdouble);
Changing status to NEW and asking the OJI team to look at the proposed patch and
decide if it is needed.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Will take a look at the patch after the Preview Release 2 gets out there and we
have time to look at OJI bugs again.  Will probably get to this next week.
Status: NEW → ASSIGNED
I've tried a similar patch for this in my tree, and plan on check it in soon. 
Watch bug #39050 for further details.


*** This bug has been marked as a duplicate of 39050 ***
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
I looked at Bug 39050.  If you use that patch, please make sure you do all the
cases I submitted (i.e. the "beauty" part) and not just the double /float case.
Also, please remember to fix occurrences in both nsJNI.cpp and ProxyJNI.cpp
since I did not see both files mentioned in that bug report.

Thanks,

Kevin
nsJNI.cpp should be CVS removed, it was the orginal name of the ProxyJNI.cpp 
file.
Verified dupe. Looks like all the cases covered here were covered by the fix to
39050.
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.