jetma / jav8

Automatically exported from code.google.com/p/jav8
0 stars 0 forks source link

The Env::NewObject routine uses an uninitialized variable for var args #32

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compiler warning about uninitialized args var in NewObject routine

What is the expected output? What do you see instead?
No warning, correct code

What version of the product are you using? On what operating system?
Latest code from SVN as of 11/3/2014

Please provide any additional information below.

The NewObject routine needs to pass it's variable arguments to the JNI 
NewObjectV function.

Here is the current code.  Note that the args variable is never initialized.

jobject Env::NewObject(const char *name, const char *sig, ...)
{
  jclass clazz = FindClass(name);
  jmethodID cid = GetMethodID(clazz, "<init>", sig);
  va_list args;

  return m_env->NewObjectV(clazz, cid, args);
}

To properly pass the var args to another function I think you need to do the 
following:

jobject Env::NewObject(const char *name, const char *sig, ...)
{
  jclass clazz = FindClass(name);
  jmethodID cid = GetMethodID(clazz, "<init>", sig);
  va_list args;
  jobject result;

  va_start(args, sig);
  result = m_env->NewObjectV(clazz, cid, args);
  va_end(args);
  return result;
}

Original issue reported on code.google.com by rje...@universalbits.com on 3 Nov 2014 at 6:52