[GRASS5] [patch] resize bug in X monitor

Hi,

the below patch corrects a bunnyhop error in XDRIVER and updates
G_malloc() a little.

The bunnyhop error caused a bus error when resizing an X monitor on
freebsd, and the update to G_malloc() ensures that returned memory
is initialized to zeros (which not all malloc()s can be trusted to
do).

Magnus

Index: src/display/devices/XDRIVER/XDRIVER24/Serve_Xevent.c

RCS file: /home/grass/grassrepository/grass/src/display/devices/XDRIVER/XDRIVER2
4/Serve_Xevent.c,v
retrieving revision 1.7
diff -c -r1.7 Serve_Xevent.c
*** src/display/devices/XDRIVER/XDRIVER24/Serve_Xevent.c 16 Feb 2002 07:2
2:56 -0000 1.7
--- src/display/devices/XDRIVER/XDRIVER24/Serve_Xevent.c 30 Apr 2002 17:1
8:15 -0000
***************
*** 234,240 ****
  
  static void handleResizeEvent(void)
  {
! PAD *curpad;
      char buf[64];
      XWindowAttributes xwa;
      XGCValues gc_values;
--- 234,241 ----
  
  static void handleResizeEvent(void)
  {
! FILE *_f;
! PAD *curpad, *nextpad;
      char buf[64];
      XWindowAttributes xwa;
      XGCValues gc_values;
***************
*** 254,262 ****
      delete_item(curpad,"cur_w");
  
      /* delete all other pads */
! for ( curpad = pad_list(); curpad != NULL; curpad = curpad->next )
        if ( *curpad->name )
            delete_pad(curpad);
  
      curpad = NULL;
  
--- 255,266 ----
      delete_item(curpad,"cur_w");
  
      /* delete all other pads */
! for ( curpad = pad_list(); curpad != NULL; curpad = nextpad )
! {
! nextpad = curpad->next;
        if ( *curpad->name )
            delete_pad(curpad);
+ }
  
      curpad = NULL;
  
Index: src/libes/gis/alloc.c

RCS file: /home/grass/grassrepository/grass/src/libes/gis/alloc.c,v
retrieving revision 1.2
diff -c -r1.2 alloc.c
*** src/libes/gis/alloc.c 22 Jan 2002 12:01:06 -0000 1.2
--- src/libes/gis/alloc.c 30 Apr 2002 17:18:45 -0000
***************
*** 59,65 ****
      if (n <= 0) n = 1; /* make sure we get a valid request */
  
      buf = malloc(n);
! if(buf) return buf;
  
      G_fatal_error ("G_malloc: out of memory");
      return NULL;
--- 59,68 ----
      if (n <= 0) n = 1; /* make sure we get a valid request */
  
      buf = malloc(n);
! if(buf) {
! bzero(buf, n); /* Don't trust malloc to initialize buffer. */
! return buf;
! }
  
      G_fatal_error ("G_malloc: out of memory");
      return NULL;

On Tue, 30 Apr 2002, I wrote:

Subject: [GRASS5] [patch] resize bug in X monitor

Hi,

the below patch corrects a bunnyhop error in XDRIVER and updates
G_malloc() a little.

The bunnyhop error caused a bus error when resizing an X monitor on
freebsd, and the update to G_malloc() ensures that returned memory
is initialized to zeros (which not all malloc()s can be trusted to
do).

Only, the patch I sent also included a redundant local variable (FILE *_f)
that helped me diagnose the bunnyhop. Ack...

See the patch below instead.

Pardon my spamming,
Magnus

Index: src/display/devices/XDRIVER/XDRIVER24/Serve_Xevent.c

RCS file: /home/grass/grassrepository/grass/src/display/devices/XDRIVER/XDRIVER2
4/Serve_Xevent.c,v
retrieving revision 1.7
diff -c -r1.7 Serve_Xevent.c
*** src/display/devices/XDRIVER/XDRIVER24/Serve_Xevent.c 16 Feb 2002 07:2
2:56 -0000 1.7
--- src/display/devices/XDRIVER/XDRIVER24/Serve_Xevent.c 30 Apr 2002 17:1
8:15 -0000
***************
*** 234,240 ****
  
  static void handleResizeEvent(void)
  {
! PAD *curpad;
      char buf[64];
      XWindowAttributes xwa;
      XGCValues gc_values;
--- 234,241 ----
  
  static void handleResizeEvent(void)
  {
! PAD *curpad, *nextpad;
      char buf[64];
      XWindowAttributes xwa;
      XGCValues gc_values;
***************
*** 254,262 ****
      delete_item(curpad,"cur_w");
  
      /* delete all other pads */
! for ( curpad = pad_list(); curpad != NULL; curpad = curpad->next )
        if ( *curpad->name )
            delete_pad(curpad);
  
      curpad = NULL;
  
--- 255,266 ----
      delete_item(curpad,"cur_w");
  
      /* delete all other pads */
! for ( curpad = pad_list(); curpad != NULL; curpad = nextpad )
! {
! nextpad = curpad->next;
        if ( *curpad->name )
            delete_pad(curpad);
+ }
  
      curpad = NULL;
  
Index: src/libes/gis/alloc.c

RCS file: /home/grass/grassrepository/grass/src/libes/gis/alloc.c,v
retrieving revision 1.2
diff -c -r1.2 alloc.c
*** src/libes/gis/alloc.c 22 Jan 2002 12:01:06 -0000 1.2
--- src/libes/gis/alloc.c 30 Apr 2002 17:18:45 -0000
***************
*** 59,65 ****
      if (n <= 0) n = 1; /* make sure we get a valid request */
  
      buf = malloc(n);
! if(buf) return buf;
  
      G_fatal_error ("G_malloc: out of memory");
      return NULL;
--- 59,68 ----
      if (n <= 0) n = 1; /* make sure we get a valid request */
  
      buf = malloc(n);
! if(buf) {
! bzero(buf, n); /* Don't trust malloc to initialize buffer. */
! return buf;
! }
  
      G_fatal_error ("G_malloc: out of memory");
      return NULL;

Magnus B{ckstr|m wrote:

the below patch corrects a bunnyhop error in XDRIVER and updates
G_malloc() a little.

The bunnyhop error caused a bus error when resizing an X monitor on
freebsd,

OK; I'll fix that.

and the update to G_malloc() ensures that returned memory
is initialized to zeros (which not all malloc()s can be trusted to
do).

This shouldn't be necessary. Code which requires that the memory is
zeroed should call G_calloc().

--
Glynn Clements <glynn.clements@virgin.net>

On Tue, Apr 30, 2002 at 07:56:19PM +0100, Glynn Clements wrote:

Magnus B{ckstr|m wrote:

[snip]

> and the update to G_malloc() ensures that returned memory
> is initialized to zeros (which not all malloc()s can be trusted to
> do).

This shouldn't be necessary. Code which requires that the memory is
zeroed should call G_calloc().

Not to mention that bzero() is a BSDism which may not be available
everywhere. Use memset instead.

--
Eric G. Miller <egm2@jps.net>