Possible bug in g-wrap gw-* code

Matthew Vanecek mevanecek@yahoo.com
19 Oct 2002 11:43:53 -0500


--=-noFtGy7UQ8h8Z8DgaGOt
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

There appears to be a bug in the way some of the scheme files are
converted to C.  I'm getting a lot of warnings when compiling from cvs.=20
I explored some of the C code to verify the warnings, and I found that
the warnings are indeed valid warnings.  The variables in questioned
could definitely be used uninitialized.  Pasted below is an example
function and the warning.  I've stripped out most of the irrelevant
code, but the if/else structures are the same. I indented with 'indent
-i2 -bli0 -cbi0 -cli2 -nut -br -ce' to make the code readable.

You'll notice that gw__c_arg0 is initialized in an else{} statement, and
further down it is used as an argument for
kvp_frame_get_slot_path_gslist().  Where gw__c_arg0 is used, it is
couched in an if based on qw__error_status.  Intuitively you can tell
that kvp_frame_get_slot_path_gslist() won't ever be executed with an
uninitialized gw__c_arg0.  However, due to the complexity of the code,
what with different values being set by calls to other functions, the
compiler cannot know that gw__c_arg0 will always be initialized prior to
use.  The compiler, unfortunately, cannot use intuition to generate code
(unless someone at MIT has made an AI compiler?).  I don't think any
compiler could compile this code without generating a warning (unless
you turned warnings off via a compiler switch).

Since we don't want to turn warnings off, but we don't really want to
see warnings for things we the developers have ostensibly accounted for,
the proper thing to do would be to initialize these variables to NULL in
the declaration.  That would quiesce the compiler warnings without
adversely affecting the code.  I have no idea how to do that in the
scheme spec files, myself.

Then we can start tracking down the "unused variable" and "defined but
not used" warnings...

Here's a warning:
gw-kvp.c:566: warning: `gw__c_arg0' might be used uninitialized in this
function

Here's the flow control structure that generated the warning:

-------------------------------BEGIN CODE-------------------------------
static SCM
gw__tmp551_kvp_frame_get_slot_path_gslist_wrapper (SCM gw__scm_arg0,
                                                   SCM gw__scm_arg1)
{
  kvp_frame *gw__c_arg0;

  if (gw__error_status =3D=3D GW__ERR_NONE) {
    if () {
       gw__error_status =3D GW__ERR_ARG_TYPE;
    } else {
      if (SCM_FALSEP (gw__scm_arg0))
        gw__c_arg0 =3D NULL;
      else
        gw__c_arg0 =3D gw_wcp_get_ptr (gw__scm_arg0);
    }
    if ((gw__error_status =3D=3D GW__ERR_TYPE)) {
    } else if ((gw__error_status =3D=3D GW__ERR_RANGE)) {
    }
    gw__arg_pos++;
    if (gw__error_status =3D=3D GW__ERR_NONE) {
      {
        gw__c_arg1 =3D NULL;
      }
      if ((gw__error_status =3D=3D GW__ERR_TYPE)) {
      } else if ((gw__error_status =3D=3D GW__ERR_RANGE)) {
      }
      if (gw__error_status =3D=3D GW__ERR_NONE) {
        /* no pre-call result code requested! */
        if (gw__error_status =3D=3D GW__ERR_NONE) {
          gw__c_result =3D kvp_frame_get_slot_path_gslist (gw__c_arg0,
gw__c_arg1);
        }
      }
    }
  }
  return gw__scm_result;        /* shut the compiler up */
}
-------------------------------END   CODE-------------------------------

Anyhow, the above type of warnings generate over 1000 lines of warnings,
so it should be taken care of.

Thanks,
--=20
Matthew Vanecek
perl -e 'print
$i=3Dpack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
***************************************************************************=
*****
For 93 million miles, there is nothing between the sun and my shadow
except me.
I'm always getting in the way of something...

--=-noFtGy7UQ8h8Z8DgaGOt
Content-Type: application/DEFANGED-166927; name="signature_asc.DEFANGED-166927"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA9sYvJOMmiB1jXEBsRAlJbAKCPMIRHDIcDZFU2oGkH2ULa8kbVaACcC59k
EOnLQOjIS1PNA9tMRwnHno8=
=4tYN
-----END PGP SIGNATURE-----

--=-noFtGy7UQ8h8Z8DgaGOt--