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 642944 - NULL key lookup using g_hash_table_lookup_extended()
NULL key lookup using g_hash_table_lookup_extended()
Status: RESOLVED NOTABUG
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-02-22 05:05 UTC by Andreas J. Guelzow
Modified: 2011-02-25 15:42 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Andreas J. Guelzow 2011-02-22 05:05:35 UTC
In gnumeric we had in xlsx export:
----------------------------------------------------
	authors = g_hash_table_new (g_str_hash, g_str_equal);
	for (ptr = objects; ptr; ptr = ptr->next) {
		authorname = cell_comment_author_get (CELL_COMMENT (ptr->data));
		if (!g_hash_table_lookup_extended (authors, authorname, NULL, NULL))
			g_hash_table_insert (authors, (gpointer) authorname, GUINT_TO_POINTER (author++));
	}
----------------------------------------------------
If authorname happens to be NULL this crashed inside g_hash_table_lookup_extended although its documentation clearly indicates that NULL can be used as a lookup_key:

Program received signal SIGSEGV, Segmentation fault.
0x01018733 in g_str_hash (v=0x0) at gstring.c:142
142	  for (p = v; *p != '\0'; p++)

We have the backtrace:

  • #0 g_str_hash
    at gstring.c line 142
  • #1 g_hash_table_lookup_node
    at ghash.c line 312
  • #2 g_hash_table_lookup_extended
    at ghash.c line 935
  • #3 xlsx_write_comments
    at xlsx-write.c line 1355
  • #4 xlsx_write_sheet
    at xlsx-write.c line 1413
  • #5 xlsx_write_workbook
    at xlsx-write.c line 1566
  • #6 xlsx_file_save

Comment 1 Matthias Clasen 2011-02-25 15:42:16 UTC
You can only pass NULL if your hash and equal functions are NULL-safe.

I've clarified the docs.