summary refs log tree commit diff stats
path: root/src/fe-gtk/chanview.c
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-12-28 06:37:25 -0500
committerTingPing <tingping@tingping.se>2014-12-28 06:44:44 -0500
commit83032b1aa3c3e5910c5cfd3e0ea1d25827f56475 (patch)
tree9be32a04d3070eac82177e11d182dad40a63baa7 /src/fe-gtk/chanview.c
parentc4cb1b25ec06a5b0cb718c6f8e74630df9a9bc64 (diff)
Use glib for all allocations
- Removes need to check for malloc failure
- Removes need for NULL checks on free
- Adds checks for integer overflows
- Removes some extra memset calls
- Removes chance of mixing libc and glib malloc/free
Diffstat (limited to 'src/fe-gtk/chanview.c')
-rw-r--r--src/fe-gtk/chanview.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/fe-gtk/chanview.c b/src/fe-gtk/chanview.c
index 4c50d922..e5556d9f 100644
--- a/src/fe-gtk/chanview.c
+++ b/src/fe-gtk/chanview.c
@@ -111,9 +111,8 @@ truncate_tab_name (char *name, int max)
 	if (max > 2 && g_utf8_strlen (name, -1) > max)
 	{
 		/* truncate long channel names */
-		buf = malloc (strlen (name) + 4);
-		strcpy (buf, name);
-		g_utf8_offset_to_pointer (buf, max)[0] = 0;
+		buf = g_malloc (strlen (name) + 4);
+		g_utf8_strncpy (buf, name, max);
 		strcat (buf, "..");
 		return buf;
 	}
@@ -231,7 +230,7 @@ chanview_free_ch (chanview *cv, GtkTreeIter *iter)
 	chan *ch;
 
 	gtk_tree_model_get (GTK_TREE_MODEL (cv->store), iter, COL_CHAN, &ch, -1);
-	free (ch);
+	g_free (ch);
 }
 
 static void
@@ -251,7 +250,7 @@ chanview_destroy (chanview *cv)
 		gtk_widget_destroy (cv->box);
 
 	chanview_destroy_store (cv);
-	free (cv);
+	g_free (cv);
 }
 
 static void
@@ -267,7 +266,7 @@ chanview_new (int type, int trunc_len, gboolean sort, gboolean use_icons,
 {
 	chanview *cv;
 
-	cv = calloc (1, sizeof (chanview));
+	cv = g_new0 (chanview, 1);
 	cv->store = gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_POINTER,
 											  PANGO_TYPE_ATTR_LIST, GDK_TYPE_PIXBUF);
 	cv->style = style;
@@ -368,7 +367,7 @@ chanview_add_real (chanview *cv, char *name, void *family, void *userdata,
 
 	if (!ch)
 	{
-		ch = calloc (1, sizeof (chan));
+		ch = g_new0 (chan, 1);
 		ch->userdata = userdata;
 		ch->family = family;
 		ch->cv = cv;
@@ -401,7 +400,7 @@ chanview_add (chanview *cv, char *name, void *family, void *userdata, gboolean a
 	ret = chanview_add_real (cv, new_name, family, userdata, allow_closure, tag, icon, NULL, NULL);
 
 	if (new_name != name)
-		free (new_name);
+		g_free (new_name);
 
 	return ret;
 }
@@ -492,7 +491,7 @@ chan_rename (chan *ch, char *name, int trunc_len)
 	ch->cv->trunc_len = trunc_len;
 
 	if (new_name != name)
-		free (new_name);
+		g_free (new_name);
 }
 
 /* this thing is overly complicated */
@@ -645,7 +644,7 @@ chan_remove (chan *ch, gboolean force)
 
 	ch->cv->size--;
 	gtk_tree_store_remove (ch->cv->store, &ch->iter);
-	free (ch);
+	g_free (ch);
 	return TRUE;
 }