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 585521 - wrong size allocation in RecentManager::add_item
wrong size allocation in RecentManager::add_item
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.16.x
Other All
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2009-06-12 04:33 UTC by Hakim Bellam
Modified: 2009-06-16 16:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to fix RecentManager::add_item (776 bytes, text/plain)
2009-06-12 04:35 UTC, Hakim Bellam
Details

Description Hakim Bellam 2009-06-12 04:33:56 UTC
it should be sizeof(*glib) instead of sizeof(glib), this patch fixes a crash in subtitleeditor and probably other applications that use RecentManager
Comment 1 Hakim Bellam 2009-06-12 04:35:49 UTC
Created attachment 136385 [details]
patch to fix RecentManager::add_item
Comment 2 Murray Cumming 2009-06-15 14:05:39 UTC
-  c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar)));
+  c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(*gchar)));


I asume that sizeof(*gchar) is the same as sizeof(gchar*), in which case this makes sense. This is likely to be a problem on 64-bit systems, right?

Comment 3 Daniel Elstner 2009-06-15 20:42:55 UTC
I think sizeof(*gchar) is just a syntax error, but sizeof(gchar*) is probably what was meant.  sizeof(gchar) is always 1 and definitely wrong in this context.

Alternatively, one may just use g_new().
Comment 4 Hakim Bellam 2009-06-15 20:43:56 UTC
sorry i made several typos, anyway i meant it should be sizeof(gchar*) and yes i have 64-bit system
Comment 5 Hakim Bellam 2009-06-15 21:03:24 UTC
Comment on attachment 136385 [details]
patch to fix RecentManager::add_item

>--- gtkmm-2.16.0/gtk/src/recentmanager.ccg	2009-06-12 04:32:58.000000000 +0100
>+++ gtkmm-2.16.0-patched/gtk/src/recentmanager.ccg	2009-06-12 05:28:12.000000000 +0100
>@@ -34,7 +34,7 @@ bool RecentManager::add_item(const Glib:
>   c_data.mime_type = const_cast<gchar*>(data.mime_type.c_str());
>   c_data.app_name = const_cast<gchar*>(data.app_name.c_str());
>   c_data.app_exec = const_cast<gchar*>(data.app_exec.c_str());
>-  c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar)));
>+  c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar*)));
>   for(unsigned int i = 0; i < data.groups.size(); ++ i)
>     c_data.groups[i] = const_cast<gchar*>(data.groups[i].c_str());
>   c_data.groups[data.groups.size()] = NULL;
Comment 6 Daniel Elstner 2009-06-15 21:34:05 UTC
Just to preempt confusion: This a bug on any machine and in no way limited to 64 bit systems.

On a side note, the code excerpt looks suspiciously like something that needs to be reworked anyway. Reasonable uses of g_malloc() in non-generated wrapper code are rare.
Comment 7 Murray Cumming 2009-06-16 16:57:47 UTC
Applied in git Thanks. Please patch the ChangeLog in future.