After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 587683 - Casting Arrays generates bogus code
Casting Arrays generates bogus code
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-07-03 13:33 UTC by Simon Budig
Modified: 2009-08-16 21:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon Budig 2009-07-03 13:33:07 UTC
Casting Arrays can result in code that crashes the application.

The following minimal vala example shows the problem (vala-git as of today):

int
main (string[] args)
{
  char[]  signed_array;
  uchar[] unsigned_array;

  signed_array = new char[20];
  unsigned_array = (uchar[]) signed_array;

  return 0;
}

The generated code contains the following code:

_vala_array_dup1 (_tmp1_, -1)

but (probably) vala_array_dup1 takes an unsigned long integer as parameter for the array size, resulting in the attempt to malloc 2^32-1 bytes, which obviously fails:

GLib-ERROR **: /build/buildd-glib2.0_2.20.1-2-i386-hGzT8z/glib2.0-2.20.1/glib/gmem.c:136: failed to allocate 4294967295 bytes
aborting...
Aborted

Compilation of the vala-code above does not yield any warnings.
Comment 1 Simon Budig 2009-07-03 14:02:43 UTC
A similiar problem also happens with weak references. While this example does not crash it gives unexpected results for the array length:

int
main (string[] args)
{
  char[]  signed_array;
  weak uchar[] unsigned_array;

  signed_array = new char[20];
  unsigned_array = (uchar[]) signed_array;

  stdout.printf ("array sizes: signed: %d, unsigned: %d\n",
                 signed_array.length, unsigned_array.length);

  return 0;
}
Comment 2 Jürg Billeter 2009-08-16 21:21:34 UTC
commit edcd069d6b0b7b9e1ff2797d45ccbafe910a1357
Author: Jürg Billeter <j@bitron.ch>
Date:   Wed Jul 29 23:29:09 2009 +0200

    Retain array length across casts