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 145485 - Dragging 31st of month produces errors
Dragging 31st of month produces errors
Status: RESOLVED DUPLICATE of bug 145134
Product: gtk+
Classification: Platform
Component: Widget: Other
2.4.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-07-06 03:23 UTC by tbpub
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: 2.3/2.4



Description tbpub 2004-07-06 03:23:21 UTC
When you select the 31st of any month and drag it around, a bunch of messages
print thusly:

tupaper:2738): GLib-CRITICAL **: file gdate.c: line 57 (g_date_new_dmy):
assertion `g_date_valid_dmy (day, m, y)' failed

(tupaper:2738): GLib-CRITICAL **: file gdate.c: line 1360 (g_date_strftime):
assertion `d != NULL' failed

I grepped the source of glib and saw that no other code in glib calles
g_date_new_dmy, and I grepped source of gtk and saw that no other code besides
gtk_calendar_drag_data_get in gtkcalendar.c calls g_date_new_dmy, and my code
doesn't call it, and it happens when you drag the 31st.  So it looks like a bug
in gtkcalendar.
Comment 1 tbpub 2004-07-06 03:38:05 UTC
Repro case:

#include <gtk/gtk.h>

int main (int argc, char* argv[]) {
  gtk_set_locale ();
  gtk_init (&argc, &argv);
  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  GtkWidget *calendar = gtk_calendar_new ();
  gtk_container_add (GTK_CONTAINER (window), calendar);
  gtk_widget_show_all (window);
  gtk_main ();
  return 0;
}

// Build and drag the 31st.  Built with glib 2.4.2, Debian Revision 1,
// gtk 2.4.3, Debian Revision 2, on Debian sid.
Comment 2 Matthias Clasen 2004-07-06 04:23:09 UTC
I can't reproduce this. To help you further, we would need at least the values of 
day, m, and y which trigger the assertion.
Comment 3 tbpub 2004-07-06 06:51:42 UTC
I copied the above to a file called "test.c" and built it with:

gcc `pkg-config --cflags --libs glib-2.0 gtk+-x11-2.0` -o test test.c

The pkg-config above returns:
$ pkg-config --cflags --libs glib-2.0 gtk+-x11-2.0
-DXTHREADS -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/X11R6/include
-I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2 
-Wl,--export-dynamic -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm
-lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

I'm not expert at using gdb, so I don't know how to set a breakpoint and see the
specific invalid day, m, y which are being passed; but it happens when I drag
**any** 31st of any month (or at least all I've tried).  It doesn't happen when
the last day of the month is the 30th; or on the first; but it happens with
*every* 31st day.

I'm assuming I don't have a debug build of gtk installed on my machine; plus as
I said I don't know gdb.  I'll add a g_printerr statement at the offending line
printing out d,m,y, and see what values are being passed.  Hold on a second.
Comment 4 tbpub 2004-07-06 07:27:28 UTC
$ ./test >>>30,6,2004
>>>30,6,2004
>>>30,6,2004
>>>31,6,2004

(test:29327): GLib-CRITICAL **: file gdate.c: line 57 (g_date_new_dmy):
assertion `g_date_valid_dmy (day, m, y)' failed

(test:29327): GLib-CRITICAL **: file gdate.c: line 1360 (g_date_strftime):
assertion `d != NULL' failed

Note that these dates came out when dragging JULY 30, 2004 and JULY 31, 2004,
respectively.  I got the above by adding g_printerr(">>>%d,%d,%d\n",
calendar->selected_day, calendar->month, calendar->year) to
gtk_calendar_drag_data_get in gtkcalendar.c right before the call to
g_date_new_dmy (calendar->selected_day, calendar->month, calendar->year);

I think I see the problem: the above should be:

g_date_new_dmy (calendar->selected_day, calendar->month + 1, calendar->year);

I wrote a new test case:

#include <gtk/gtk.h>

int main (int argc, char* argv[]) {
  gtk_set_locale ();
  gtk_init (&argc, &argv);
  g_print(">1\n");
  GDate *bad = g_date_new_dmy (31, 6, 2004);
  g_print(">2\n");
  GDate *good = g_date_new_dmy (31, 7, 2004);
  g_print(">3\n");
  return 0;
}

$ ./test 
>1

(test:29484): GLib-CRITICAL **: file gdate.c: line 57 (g_date_new_dmy):
assertion `g_date_valid_dmy (day, m, y)' failed
>2
>3

So the bug is that you need to pass calendar->month + 1 instead of
calendar->month.  As I said, Debian Sid has gtk 2.4.3 installed.  This may be
fixed in 2.6, I dunno, Debian doesn't have that.
Comment 5 tbpub 2004-07-06 07:29:25 UTC
$ diff -u gtkcalendar.c.orig gtkcalendar.c
--- gtkcalendar.c.orig  2004-07-06 00:28:26.000000000 -0700
+++ gtkcalendar.c       2004-07-06 00:28:39.000000000 -0700
@@ -3371,7 +3371,7 @@
   gchar str[128];
   gsize len;

-  date = g_date_new_dmy (calendar->selected_day, calendar->month, calendar->year);
+  date = g_date_new_dmy (calendar->selected_day, calendar->month + 1,
calendar->year);
   len = g_date_strftime (str, 127, "%x", date);
   gtk_selection_data_set_text (selection_data, str, len);
Comment 6 Owen Taylor 2004-07-06 11:44:59 UTC
Was fixed a little while ago in CVS, actually.


*** This bug has been marked as a duplicate of 145134 ***
Comment 7 tbpub 2004-07-06 15:11:14 UTC
Wow, we both noticed it within a week of each other.