Re: glib/gdataset.c (quarky / stringy stuff)



On Mon, Oct 20, 2014 at 10:39:54AM +0100, John Emmas wrote:
Hi guys - please forgive me if this isn't the right mailing list for
glib questions.  I'd like to ask a question about a recent change in
'glib/gdataset.c'.  Up until a week or so ago, the code around line
1031 looked like this:-

      if (strcmp (g_quark_to_string (data->key), key) == 0)
      {
        res = data->data;
        break;
      }

Some time in the dim and distant past (to fix a problem which I
can't remember any more) I changed my local copy to look like this:-

      if (g_quark_to_string (data->key) != 0) /* This line added by
me !!! */
        if (strcmp (g_quark_to_string (data->key), key) == 0)
        {
          res = data->data;
          break;
        }

but after an update this morning I noticed that the official code
has recently been changed to this:-

        if (g_strcmp0 (g_quark_to_string (data->key), key) == 0)
        {
          res = data->data;
          break;
        }

Is that change effectively equivalent to what I did locally?

No.  As far as I can tell you can pass NULL key to g_datalist_get_data()
after this change.  If you do so and g_quark_to_string(data->key)
returns NULL (for whatever reason), the two NULLs will be considered
equal by g_strcmp0().  Whereas your change makes a NULL not-equal to
everything, even another NULL.

Regards,

Yeti



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