nanogui: textfield_settext free bug !


Previous by date: 2 Feb 2000 23:55:15 -0000 RTEMS GUI, Erwin Rol
Next by date: 2 Feb 2000 23:55:15 -0000 Re: RTEMS GUI, Greg Haerr
Previous in thread:
Next in thread: 2 Feb 2000 23:55:15 -0000 Re: textfield_settext free bug !, Greg Haerr

Subject: textfield_settext free bug !
From: Chris Johns ####@####.####
Date: 2 Feb 2000 23:55:15 -0000
Message-Id: <3898C173.A6F4CDBB@acm.org>

Hi all,

I noticed this in `ntextfield.c'. Is this a bug ?

static void textfield_settext (NTEXTFIELD * this, const char * text)
{   
   int maxsize;

   if (text && strlen(text) > 256) maxsize = strlen(text) + 1;
   else maxsize = 256;

   if (this->maxsize < maxsize) {
      if (this->textbuf) free(this->textbuf);
      if (this->textbuf = malloc(maxsize)) {
	 this->textbuf[0] = '\0';
	 this->maxsize = maxsize;
      } else this->maxsize = 0;
   }
   
   if (!this->textbuf) free(this->textbuf); <<<< !!!!
   if (text) this->textbuf = strdup(text);
   else this->textbuf = 0;

   if (text && this->textbuf) strcpy(this->textbuf,text);
   this->curpos = 0;
   this->firstpos = 0;
   
   n_widget_repaint(this);

}

I fail to follow what this section of code does :

   if (!this->textbuf) free(this->textbuf);
   if (text) this->textbuf = strdup(text);
   else this->textbuf = 0;


-- 
 Chris Johns, ####@####.####

Previous by date: 2 Feb 2000 23:55:15 -0000 RTEMS GUI, Erwin Rol
Next by date: 2 Feb 2000 23:55:15 -0000 Re: RTEMS GUI, Greg Haerr
Previous in thread:
Next in thread: 2 Feb 2000 23:55:15 -0000 Re: textfield_settext free bug !, Greg Haerr


Powered by ezmlm-browse 0.20.