The code below is giving me some strange errors when run in valgrind:
GtkWidget * text = gtk_source_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
gtk_text_view_set_monospace(GTK_TEXT_VIEW(text), TRUE);
gtk_source_view_set_insert_spaces_instead_of_tabs(GTK_SOURCE_VIEW(text), TRUE);
gtk_source_view_set_tab_width(GTK_SOURCE_VIEW(text), 4);
gtk_source_view_set_show_line_numbers(GTK_SOURCE_VIEW(text), TRUE);
main = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(main), text);
GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
GtkSourceSearchContext * context = gtk_source_search_context_new(GTK_SOURCE_BUFFER(buffer), NULL);
GtkSourceLanguageManager * manager = gtk_source_language_manager_get_default();
GtkSourceLanguage * language = gtk_source_language_manager_guess_language (manager, filename, content_type);
gtk_source_search_context_set_highlight(context, TRUE);
gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buffer), language);
gtk_source_search_settings_set_wrap_around(gtk_source_search_context_get_settings(context), TRUE);
First off, the code in question appears to run fine when I simply run it, but when I run it in valgrind I am spammed with the “Conditional jump or move depends on uninitialised value” error. At first I thought this might be one of the data structures I have implemented which are being compared, but when I inspected further I found that error is arising from a realloc done by the gtk_source_buffer_set_language call:
==11453== Conditional jump or move depends on uninitialised value(s)
==11453== at 0xD1403C8: ???
==11453== by 0xB0D9CBF: ???
==11453== Uninitialised value was created by a heap allocation
==11453== at 0x4848B80: realloc (vg_replace_malloc.c:1690)
==11453== by 0x57D53D2: g_realloc (gmem.c:201)
==11453== by 0x57F02C2: UnknownInlinedFun (gstring.c:92)
==11453== by 0x57F02C2: g_string_expand (gstring.c:78)
==11453== by 0x57F0330: g_string_sized_new (gstring.c:123)
==11453== by 0x57E87FF: g_regex_replace_eval (gregex.c:3459)
==11453== by 0x48E1244: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1047)
==11453== by 0x48E1244: expand_regex.constprop.0 (gtksourcelanguage-parser-2.c:1190)
==11453== by 0x48DCEB7: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1306)
==11453== by 0x48DCEB7: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1552)
==11453== by 0x48DCEB7: file_parse.lto_priv.0 (gtksourcelanguage-parser-2.c:1682)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1360)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1430)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1532)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1556)
==11453== by 0x48DE3A6: file_parse.lto_priv.0 (gtksourcelanguage-parser-2.c:1682)
==11453== by 0x48ABC4E: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1820)
==11453== by 0x48ABC4E: gtk_source_language_parse_file.lto_priv.0 (gtksourcelanguage.c:735)
==11453== by 0x4899504: UnknownInlinedFun (gtksourcelanguage.c:762)
==11453== by 0x4899504: gtk_source_buffer_set_language (gtksourcebuffer.c:1832)
==11453== by 0x1121FE: newpage (explorer.c:96)
==11453== by 0x11252D: selected (explorer.c:138)
Does anyone know why I am getting this error? I’ve made sure that the text buffer generated by the source view is indeed a valid source buffer, and I have no idea how to guarantee that the language is valid aside the fact that the code runs when I don’t run with valgrind, only valgrind is giving me this strange error.