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 571322 - length not correctly computed for array elements of array of array of strings
length not correctly computed for array elements of array of array of strings
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: D-Bus
0.5.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-02-11 17:27 UTC by Zeeshan Ali
Modified: 2010-10-16 13:43 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Zeeshan Ali 2009-02-11 17:27:41 UTC
The following code results in a segfault due to the fact that length of array inside the array of array of strings is evaluated to '-1'.


   ...
            string[][] search_result = this.search.Query (
                                                   0,
                                                   this.category,
                                                   this.get_metadata_keys (),
                                                   "",
                                                   new string[0],
                                                   "",
                                                   false,
                                                   new string[0],
                                                   false,
                                                   (int) offset,
                                                   (int) max_count);

            ArrayList<MediaObject> children = new ArrayList<MediaObject> ();

            /* Iterate through all items */
            for (uint i = 0; i < search_result.length; i++) {
                string child_path = search_result[i][0];
                string[] metadata = this.slice_strv_tail (search_result[i], 2);
                
                MediaObject item = this.fetch_item_by_path (child_path,
                                                            metadata);
                children.add (item);
            }   

    ...

    private string[] slice_strv_tail (string[] strv, int index) {
        string[] slice = new string[strv.length - index];
        
        for (int i = 0; i < slice.length; i++) {
            slice[i] = strv[i + index];
        }   
        
        return slice;
    }
Comment 1 Zeeshan Ali 2009-02-11 17:29:08 UTC
using this function to calculate the length of the strv in the above code make everything right:

    private int get_strv_length (string[] strv) {
        int i = 0;

        for (i = 0; strv[i] != null; i++);

        return i + 1;
    }
Comment 2 Zeeshan Ali 2009-02-11 21:10:25 UTC
The problems seems to be here:

gobject/valaccodemethodcallmodule.vala:416

Don't have any clue on how to fix it though. :(
Comment 3 Jürg Billeter 2010-10-16 13:43:09 UTC
commit cc435dd6ec069b87e986fa454e80e5fe80a0df72
Author: Jürg Billeter <j@bitron.ch>
Date:   Sat Oct 16 15:17:23 2010 +0200

    Report error when trying to use stacked arrays
    
    Stacked array support was never completed. Report an error instead of
    generating incorrect C code.
    
    Fixes bug 546603, bug 548428, bug 548429, bug 565865, bug 565872,
    bug 571322, bug 572649, and bug 576611.