[PD-cvs] pd/src g_rtext.c,1.4,1.4.4.1

IOhannes m zmölnig zmoelnig at users.sourceforge.net
Tue Jun 21 15:38:29 CEST 2005


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15813

Modified Files:
      Tag: devel_0_38
	g_rtext.c 
Log Message:
added checks for NULL-pointers


Index: g_rtext.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/g_rtext.c,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -C2 -d -r1.4 -r1.4.4.1
*** g_rtext.c	6 Sep 2004 20:20:34 -0000	1.4
--- g_rtext.c	21 Jun 2005 13:38:26 -0000	1.4.4.1
***************
*** 7,10 ****
--- 7,12 ----
  /* all changes are labeled with      iemlib      */
  
+ /* IOhannes m zmölnig (20050621): added checks for NULL-pointers */
+ 
  #include <stdlib.h>
  #include <string.h>
***************
*** 44,60 ****
  t_rtext *rtext_new(t_glist *glist, t_text *who)
  {
!     t_rtext *x = (t_rtext *)getbytes(sizeof *x);
!     int w = 0, h = 0, indx;
!     x->x_height = -1;
!     x->x_text = who;
!     x->x_glist = glist;
!     x->x_next = glist->gl_editor->e_rtext;
!     x->x_selstart = x->x_selend = x->x_active =
          x->x_drawnwidth = x->x_drawnheight = 0;
!     binbuf_gettext(who->te_binbuf, &x->x_buf, &x->x_bufsize);
!     glist->gl_editor->e_rtext = x;
!     sprintf(x->x_tag, ".x%lx.t%lx", (t_int)glist_getcanvas(x->x_glist),
!         (t_int)x);
!     return (x);
  }
  
--- 46,66 ----
  t_rtext *rtext_new(t_glist *glist, t_text *who)
  {
!   if(glist && glist->gl_editor && who)
!     {
!       t_rtext *x = (t_rtext *)getbytes(sizeof *x);
!       int w = 0, h = 0, indx;
!       x->x_height = -1;
!       x->x_text = who;
!       x->x_glist = glist;
!       x->x_next = glist->gl_editor->e_rtext;
!       x->x_selstart = x->x_selend = x->x_active =
          x->x_drawnwidth = x->x_drawnheight = 0;
!       binbuf_gettext(who->te_binbuf, &x->x_buf, &x->x_bufsize);
!       glist->gl_editor->e_rtext = x;
!       sprintf(x->x_tag, ".x%lx.t%lx", (t_int)glist_getcanvas(x->x_glist),
!               (t_int)x);
!       return (x);
!     } else
!     return 0;
  }
  
***************
*** 63,78 ****
  void rtext_free(t_rtext *x)
  {
!     if (x->x_glist->gl_editor->e_textedfor == x)
          x->x_glist->gl_editor->e_textedfor = 0;
!     if (x->x_glist->gl_editor->e_rtext == x)
          x->x_glist->gl_editor->e_rtext = x->x_next;
!     else
!     {
!         t_rtext *e2;
!         for (e2 = x->x_glist->gl_editor->e_rtext; e2; e2 = e2->x_next)
!             if (e2->x_next == x)
          {
!             e2->x_next = x->x_next;
!             break;
          }
      }
--- 69,87 ----
  void rtext_free(t_rtext *x)
  {
!   if(x){
!     if(x->x_glist && x->x_glist->gl_editor){
!       if (x->x_glist->gl_editor->e_textedfor == x)
          x->x_glist->gl_editor->e_textedfor = 0;
!       if (x->x_glist->gl_editor->e_rtext == x)
          x->x_glist->gl_editor->e_rtext = x->x_next;
!       else
          {
!           t_rtext *e2;
!           for (e2 = x->x_glist->gl_editor->e_rtext; e2; e2 = e2->x_next)
!             if (e2->x_next == x)
!               {
!                 e2->x_next = x->x_next;
!                 break;
!               }
          }
      }
***************
*** 80,100 ****
--- 89,123 ----
      freebytes(x->x_buf, x->x_bufsize);
      freebytes(x, sizeof *x);
+   }
  }
  
  char *rtext_gettag(t_rtext *x)
  {
+   if(x)
      return (x->x_tag);
+   else
+     return 0;
  }
  
  void rtext_gettext(t_rtext *x, char **buf, int *bufsize)
  {
+   if(x){
      *buf = x->x_buf;
      *bufsize = x->x_bufsize;
+   } else {
+     *buf = 0;
+     *bufsize = 0;
+   }
  }
  
  void rtext_getseltext(t_rtext *x, char **buf, int *bufsize)
  {
+   if(x){
      *buf = x->x_buf + x->x_selstart;
      *bufsize = x->x_selend - x->x_selstart;
+   } else {
+     *buf = 0;
+     *bufsize = 0;
+   }
  }
  
***************
*** 103,106 ****
--- 126,130 ----
  static int firstone(char *s, int c, int n)
  {
+   if(s) {
      char *s2 = s + n;
      int i = 0;
***************
*** 111,114 ****
--- 135,139 ----
          s++;
      }
+   }
      return (-1);
  }
***************
*** 116,119 ****
--- 141,145 ----
  static int lastone(char *s, int c, int n)
  {
+   if(s){
      char *s2 = s + n;
      while (s2 != s)
***************
*** 123,126 ****
--- 149,153 ----
          if (*s2 == c) return (n);
      }
+   }
      return (-1);
  }
***************
*** 151,154 ****
--- 178,182 ----
      int *indexp)
  {
+   if(x && heightp && indexp) {
      float dispx, dispy;
      char smallbuf[200], *tempbuf;
***************
*** 270,277 ****
--- 298,307 ----
      if (tempbuf != smallbuf)
          t_freebytes(tempbuf, 2 * x->x_bufsize + 1);
+   }
  }
  
  void rtext_retext(t_rtext *x)
  {
+   if(x){
      int w = 0, h = 0, indx;
      t_text *text = x->x_text;
***************
*** 325,328 ****
--- 355,359 ----
      }
      rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
+   }
  }
  
***************
*** 330,337 ****
--- 361,371 ----
  t_rtext *glist_findrtext(t_glist *gl, t_text *who)
  {
+   if(gl && gl->gl_editor){
      t_rtext *x = gl->gl_editor->e_rtext;
      while (x && x->x_text != who) x = x->x_next;
      if (!x) bug("glist_findrtext");
      return (x);
+   } else
+     return 0;
  }
  
***************
*** 358,361 ****
--- 392,396 ----
  void rtext_erase(t_rtext *x)
  {
+   if(x)
      sys_vgui(".x%lx.c delete %s\n", glist_getcanvas(x->x_glist), x->x_tag);
  }
***************
*** 363,366 ****
--- 398,402 ----
  void rtext_displace(t_rtext *x, int dx, int dy)
  {
+   if(x)
      sys_vgui(".x%lx.c move %s %d %d\n", glist_getcanvas(x->x_glist), 
          x->x_tag, dx, dy);
***************
*** 369,372 ****
--- 405,409 ----
  void rtext_select(t_rtext *x, int state)
  {
+   if(x){
      t_glist *glist = x->x_glist;
      t_canvas *canvas = glist_getcanvas(glist);
***************
*** 374,381 ****
--- 411,420 ----
          x->x_tag, (state? "blue" : "black"));
      canvas_editing = canvas;
+   }
  }
  
  void rtext_activate(t_rtext *x, int state)
  {
+   if(x){
      int w = 0, h = 0, indx;
      t_glist *glist = x->x_glist;
***************
*** 399,402 ****
--- 438,442 ----
      }
      rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
+   }
  }
  
***************
*** 405,408 ****
--- 445,451 ----
      int w = 0, h = 0, indx, i, newsize, ndel;
      char *s1, *s2;
+ 
+     if(!x)return;
+ 
      if (keynum)
      {
***************
*** 484,487 ****
--- 527,533 ----
  {
      int w = xval, h = yval, indx;
+ 
+     if(!x)return;
+ 
      rtext_senditup(x, SEND_CHECK, &w, &h, &indx);
      if (flag == RTEXT_DOWN)





More information about the Pd-cvs mailing list