nanogui: Bug?


Previous by date: 15 Aug 2000 20:01:13 -0000 Bug?, S A McConnell
Next by date: 15 Aug 2000 20:01:13 -0000 Re: bugfix for chinese font: hzx12, 曾昭明
Previous in thread: 15 Aug 2000 20:01:13 -0000 Bug?, S A McConnell
Next in thread:

Subject: Re: Bug?
From: Alex Holden ####@####.####
Date: 15 Aug 2000 20:01:13 -0000
Message-Id: <Pine.LNX.4.04.10008152038540.569-100000@hyperspace.linuxhacker.org>

On Tue, 15 Aug 2000, S A McConnell wrote:
> This looks like a real problem. I will let someone in the know fix it.
> srvfunc.c:2059: warning: `tl' might be used uninitialized in this

It's not actually as we return before using the value if !props->title.
This looks like a cleaner way to do it though (note: untested):

--- srvfunc.c.old	Tue Aug 15 20:45:52 2000
+++ srvfunc.c	Tue Aug 15 20:53:32 2000
@@ -2029,7 +2029,7 @@
 GrSetWMProperties(GR_WINDOW_ID wid, GR_WM_PROPERTIES *props)
 {
 	GR_WINDOW *wp;
-	int tl;
+	int tl = 0;
 
 	/* Find the window structure (generate an error if it doesn't exist) */
 	wp = GsFindWindow(wid);
@@ -2042,19 +2042,18 @@
 	memcpy(&wp->properties, props, sizeof(GR_WM_PROPERTIES));
 
 	/* Remove the old title if it exists */
-	if(wp->properties.title)
+	if(wp->properties.title) {
 		free(wp->properties.title);
-
-	/* Calculate the space needed to store the new title */
-	if(props->title) tl = strlen(props->title) + 1;
-
-	/* If the new title is empty, set the pointer to NULL and return  */
-	if(!props->title || tl == 1) {
 		wp->properties.title = NULL;
-		return;
 	}
 
-	/* Otherwise, allocate some space for the new title */
+	/* If there is no title return, otherwise calculate it's length */
+	if(!props->title) return;
+	if(!(tl = strlen(props->title))) return;
+
+	tl++;	/* Add space for the NULL terminating byte */
+
+	/* Allocate some space for the new title */
 	if(!(wp->properties.title = malloc(tl))) {
 		/* We don't have that much free memory so send an error */
 		GsError(GR_ERROR_MALLOC_FAILED, wid);

-- 
--------------- Linux- the choice of a GNU generation. --------------
: Alex Holden (M1CJD)- Caver, Programmer, Land Rover nut, Radio Ham :
-------------------- http://www.linuxhacker.org/ --------------------


Previous by date: 15 Aug 2000 20:01:13 -0000 Bug?, S A McConnell
Next by date: 15 Aug 2000 20:01:13 -0000 Re: bugfix for chinese font: hzx12, 曾昭明
Previous in thread: 15 Aug 2000 20:01:13 -0000 Bug?, S A McConnell
Next in thread:


Powered by ezmlm-browse 0.20.