GLib oddities
- From: Tor Lillqvist <tml iki fi>
- To: gtk-devel-list gnome org
- Subject: GLib oddities
- Date: Fri, 19 May 2000 00:31:04 +0300 (FLE Daylight Time)
A person who is building GLib with the Borland compiler (on Win32) has
reported these oddities that the compiler emits warnings for.
The first does seem to be a real bug. In gmain.c:
static gboolean
g_idle_prepare (gpointer source_data,
GTimeVal *current_time,
gint *timeout,
gpointer user_data)
{
timeout = 0; <<--- shouldn't this be *timeout = 0;?
return TRUE;
}
In gmem.c:g_mem_chunk_free(): He claims that g_tree_search() can
return NULL, but still its return value isn't tested. Can
g_tree_search() really return NULL in this case? Would seem strange
that nobody would have noticed this earlier.
In garray.c, lots of unnecessary tests for unsigned values being >= 0...:
diff -u2 /src/glib/garray.c ./garray.c
--- /src/glib/garray.c Tue Apr 18 21:19:04 2000
+++ ./garray.c Fri May 12 23:19:14 2000
@@ -210,5 +210,5 @@
g_return_val_if_fail (array, NULL);
- g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+ g_return_val_if_fail (index < array->len, NULL);
if (index != array->len - 1)
@@ -236,5 +236,5 @@
g_return_val_if_fail (array, NULL);
- g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+ g_return_val_if_fail (index < array->len, NULL);
if (index != array->len - 1)
@@ -411,5 +411,5 @@
g_return_val_if_fail (array, NULL);
- g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+ g_return_val_if_fail (index < array->len, NULL);
result = array->pdata[index];
@@ -437,5 +437,5 @@
g_return_val_if_fail (array, NULL);
- g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+ g_return_val_if_fail (index < array->len, NULL);
result = array->pdata[index];
In gcompletion.c, an unnecessary initailisation of a variable that is
assigned before use later always anyway:
diff -u2 /src/glib/gcompletion.c ./gcompletion.c
--- /src/glib/gcompletion.c Wed Feb 24 05:13:30 1999
+++ ./gcompletion.c Sat May 13 01:33:54 2000
@@ -124,5 +124,5 @@
register gint i;
register gint plen;
- gchar* postfix=NULL;
+ gchar* postfix;
gchar* s;
Unsigned types should be used in G_STRUCT_OFFSET and G_STRUCT_MEMBER_P?
diff -u2 /src/glib/glib.h ./glib.h
@@ -191,7 +172,7 @@
*/
#define G_STRUCT_OFFSET(struct_type, member) \
- ((glong) ((guint8*) &((struct_type*) 0)->member))
+ ((gulong) ((gchar*) &((struct_type*) 0)->member))
#define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
- ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
+ ((gpointer) ((gchar*) (struct_p) + (gulong) (struct_offset)))
#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
(*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
Some unnecessary assignments, initialisations and variables:
diff -u2 /src/glib/gscanner.c ./gscanner.c
@@ -1627,5 +1626,4 @@
gstring = g_string_append_c (gstring, ch);
- ch = 0;
}
}
@@ -1697,5 +1695,4 @@
value.v_string = gstring->str;
g_string_free (gstring, FALSE);
- gstring = NULL;
}
diff -u2 /src/glib/gslist.c ./gslist.c
--- /src/glib/gslist.c Tue Apr 18 21:19:04 2000
+++ ./gslist.c Sat May 13 01:09:56 2000
@@ -391,5 +391,5 @@
{
GSList *prev = NULL;
- GSList *next = NULL;
+ GSList *next;
while (list)
diff -u2 /src/glib/gtree.c ./gtree.c
--- /src/glib/gtree.c Thu May 11 22:35:16 2000
+++ ./gtree.c Fri May 12 23:55:26 2000
@@ -694,10 +694,8 @@
{
GTreeNode *left;
- GTreeNode *right;
gint a_bal;
gint b_bal;
left = node->left;
- right = node->right;
node->left = left->right;
diff -u2 /src/glib/testgdate.c ./testgdate.c
--- /src/glib/testgdate.c Wed Dec 02 19:20:34 1998
+++ ./testgdate.c Sat May 13 00:53:34 2000
@@ -67,6 +67,6 @@
guint n_check_years = sizeof(check_years)/sizeof(GDateYear);
- guint i = 0;
- gboolean discontinuity = FALSE;
+ guint i;
+ gboolean discontinuity;
g_print("checking GDate...");
@@ -155,5 +155,5 @@
discontinuity = TRUE;
y = check_years[0];
- prev_y = G_DATE_BAD_YEAR;
+
while (i < n_check_years)
{
Cheers,
--tml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]