Re: [Vala] Bug in vala



On Fri, Dec 10, 2010 at 15:34:32 +0100, Abderrahim Kitouni wrote:
Hello,
         في ج، 10-12-2010 عند 00:40 -0300 ، كتب Erick Pérez Castellanos:
Is this a bug ???

I'm using Glib.Settings API, and specifically this:
    public bool set_strv (string key, [CCode (array_length = false)] 
string[] value)
from that class and when using as it says passing an string array as second 
parameters I'm getting a warning from the compiler:
spider_window.c: In function ‘spider_window_edit_preferences_callback’:
spider_window.c:811:3: warning: passing argument 3 of ‘g_settings_set_strv’ 
from incompatible pointer type
/usr/include/glib-2.0/gio/gsettings.h:124:25: note: expected ‘const gchar * 
const*’ but argument is of type ‘char **’

And that shouldn't happen.

"shouldn't happen" may be too strong :-)
We would like valac generated code to compile without warning, but
that's not an easy task and it doesn't bring much.

And btw, I don't see what problem there could be when passing char** to
a "const gchar* const*", maybe your compiler is a bit too paranoid? (and
maybe there is a complicated corner case I don't see).

Well, you can't cast 'char **' to 'const char **' safely (applies to any
type, not just char, of course). Consider:

    void get_message(const char **msg)
    {
        *msg = "All is wrong!";
    }

    ...
    char *msg;
    get_message(&msg);
    msg[0] = 'B'; /* OOPS! You modified the static buffer! */

The danger does NOT apply to 'char **' -> 'char const * const *', since than
nothing of the structure may be modified, but gcc may not be smart enough to
avoid the warning in this case.

-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]