[monkey-bubble: 108/753] make the strftime buffer 256 chars, stop cutting the last character, also



commit bf241f9192e659e8fb63a9202219ee4c1995d017
Author: George Lebl <jirka 5z com>
Date:   Sat May 13 19:10:59 2000 +0000

    make the strftime buffer 256 chars, stop cutting the last character, also
    
    Sat May 13 11:56:35 2000  George Lebl <jirka 5z com>
    
    	* gnome-scores.c (gnome_scores_new): make the strftime buffer 256
    	  chars, stop cutting the last character, also if strftime fails,
    	  we need to reset the buffer to something sane.

 libgnomeui/gnome-scores.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/libgnomeui/gnome-scores.c b/libgnomeui/gnome-scores.c
index 2dcc7c0..bed2926 100644
--- a/libgnomeui/gnome-scores.c
+++ b/libgnomeui/gnome-scores.c
@@ -104,7 +104,7 @@ gnome_scores_new (  guint n_scores,
 	GtkTable	*table;
 	GtkWidget	*label;
 	gchar     	tmp[10];
-	gchar     	tmp2[20];
+	gchar     	tmp2[256];
 	guint i;
 	const gchar * buttons[] = { GNOME_STOCK_BUTTON_OK, NULL };
 
@@ -145,16 +145,20 @@ gnome_scores_new (  guint n_scores,
 		gtk_table_attach_defaults ( table, gs->label_scores[i], 1, 2, i+1, i+2);
 
 		/* the localized string should fit (after replacing the %a %b
-		   etc) in ~18 chars; so drop some if needed; after all this
-		   is for games scores, there is no need for extra precision.
+		   etc) in ~18 chars.
 		   %a is abbreviated weekday, %A is full weekday,
 		   %b %B are abbreviated and full monthname, %Y is year,
 		   %d is day of month, %m is month number, %T full hour,
 		   %H hours, %M minutes, %S seconds
 		*/
-		strftime(tmp2,sizeof(tmp2),_("%a %b %d %T %Y"),
-			 localtime( &(times[i]) ));
-		tmp2[strlen(tmp2)-1]=0;
+		if(strftime(tmp2, sizeof(tmp2), _("%a %b %d %T %Y"),
+			    localtime( &(times[i]) )) == 0) {
+			/* according to docs, if the string does not fit, the
+			 * contents of tmp2 are undefined, thus just use
+			 * ??? */
+			strcpy(tmp2, "???");
+		}
+		tmp2[sizeof(tmp2)-1] = '\0'; /* just for sanity */
 		gs->label_times[i] = gtk_label_new ( tmp2 );
 		gtk_widget_show ( gs->label_times[i] );
 		gtk_table_attach_defaults ( table, gs->label_times[i], 2, 3, i+1, i+2);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]