Received: by ATHENA-PO-3.MIT.EDU (5.45/4.7) id AA15830; Mon, 8 Apr 91 11:55:34 EST
Received: from ncar.ucar.edu by ATHENA.MIT.EDU with SMTP
	id AA06201; Mon, 8 Apr 91 12:54:37 EDT
Received: from stout.atd.ucar.edu by ncar.ucar.EDU (5.65/ NCAR Central Post Office 04/10/90)
	id AA26345; Mon, 8 Apr 91 10:54:29 MDT
Message-Id: <9104081654.AA24704@stout.atd.ucar.EDU>
Received: from stout.atd.ucar.edu by stout.atd.ucar.EDU (5.65/ NCAR Mail Server 04/10/90)
	id AA24704; Mon, 8 Apr 91 10:54:24 MDT
To: Gregory Bond <gnb@bby.oz.au>, crcraig@ATHENA.MIT.EDU,
        kambiz@ATHENA.MIT.EDU
Cc: bug-at@ATHENA.MIT.EDU
Subject: Re: Anyone got a graph widget (Athena and/or Motif)? 
In-Reply-To: Your message of Fri, 05 Apr 91 14:33:57 +1000.
             <9104050434.AA14732@baby.bby.oz.au> 
Date: Mon, 08 Apr 91 10:54:23 -0600
From: vanandel@stout.atd.ucar.edu

Here are the bugs I've found and fixed:
1) core dump because of reference thru null pointer in Axis.c

2) allow "min" of linear plot to be greater than "max".  Documentation already
says this is possible, but the code prohibited it.

3) Fix the various places that IGNORED the return code from XtRealloc, to
avoid over-writing memory, and later crashing

Here are the context diffs:
*** /tmp/RCSAa24399	Mon Apr  8 10:42:24 1991
--- Axis.c	Tue Mar 26 18:27:26 1991
***************
*** 1,4 ****
! /* $Header: /local/src/AtPlotter/RCS/Axis.c,v 1.1 1991/03/21 13:43:33
vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
--- 1,4 ----
! /* $Header: /net/stout/local/src/AtPlotter/RCS/Axis.c,v 1.3 91/03/26
18:26:54 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
***************
*** 24,29 ****
--- 24,30 ----
  #include <math.h>
  #include <X11/Intrinsic.h>
  #include <X11/StringDefs.h>
+ #include <X11/Xlibint.h>	/* for max, min macros */
  
  #ifdef _AtDevelopment_
  #include "Scale.h"
***************
*** 462,469 ****
  
    if (Changed(drawGrid)) redraw = True;
  
!   if (Changed(ticLabels) || (strcmp(new->axis.ticLabels, 
! 				    new->axis.ticlabelcpy)))  {
      for (i = 0; i < new->axis.nuserticlabels; i++)
        XtFree(new->axis.userticlabels[i]);
      XtFree(new->axis.userticlabels);
--- 463,470 ----
  
    if (Changed(drawGrid)) redraw = True;
  
!   if (Changed(ticLabels) || (new->axis.ticLabels && new->axis.ticlabelcpy && 
! 	(strcmp(new->axis.ticLabels, new->axis.ticlabelcpy))))  {
      for (i = 0; i < new->axis.nuserticlabels; i++)
        XtFree(new->axis.userticlabels[i]);
      XtFree(new->axis.userticlabels);
***************
*** 695,701 ****
      double max = axis->max;
      min = ceil(min/axis->ticInterval) * axis->ticInterval;
      max = floor(max/axis->ticInterval) * axis->ticInterval;
!     w->axis.ntics = 1+(int)((max - min)/w->axis.ticInterval);
    }
    else
      axis->ntics = 1+(int)((log10(axis->max) - log10(axis->min))
--- 696,702 ----
      double max = axis->max;
      min = ceil(min/axis->ticInterval) * axis->ticInterval;
      max = floor(max/axis->ticInterval) * axis->ticInterval;
!     w->axis.ntics = 1+(int)(fabs(max - min)/w->axis.ticInterval);
    }
    else
      axis->ntics = 1+(int)((log10(axis->max) - log10(axis->min))
***************
*** 844,850 ****
      if (w->axis.scale->transform == AtTransformLINEAR)
        for(j=0; j < w->axis.subtics; j++) {
  	if ((subticval = w->axis.ticvalues[i] + 
! 	     w->axis.ticInterval / (w->axis.subtics+1)*(j+1)) <= w->axis.max)  {
  	  w->axis.subticcoords[i*(w->axis.subtics)+j] = 
  	    AtScaleUserToPixel(w->axis.scale, subticval);
  	  w->axis.totalsubtics++;
--- 845,852 ----
      if (w->axis.scale->transform == AtTransformLINEAR)
        for(j=0; j < w->axis.subtics; j++) {
  	if ((subticval = w->axis.ticvalues[i] + 
! 	     w->axis.ticInterval / (w->axis.subtics+1)*(j+1)) <= 
! 	     max(w->axis.max, w->axis.min))  {
  	  w->axis.subticcoords[i*(w->axis.subtics)+j] = 
  	    AtScaleUserToPixel(w->axis.scale, subticval);
  	  w->axis.totalsubtics++;
***************
*** 883,889 ****
   */
  void AtAxisComputeTicSpacing(AtAxisObject w, int length)
  {
-   double min;
    int i, width;
    AtAxisPart *axis = &w->axis;
    char *strcpy();
--- 885,890 ----
***************
*** 900,909 ****
    /* Calculate the tic values and place them in the ticvalues
       array of the axis structure */
    if (axis->transform == AtTransformLINEAR) {
!     min = axis->min;
!     min = ceil(min/axis->ticInterval) * axis->ticInterval;
      for(i=0;i<axis->ntics;i++)
!       axis->ticvalues[i] = ffix(min + i*axis->ticInterval);
    }
      
    else {
--- 901,911 ----
    /* Calculate the tic values and place them in the ticvalues
       array of the axis structure */
    if (axis->transform == AtTransformLINEAR) {
!     double fmin;
!     fmin = min(axis->min, axis->max);
!     fmin = ceil(fmin/axis->ticInterval) * axis->ticInterval;
      for(i=0;i<axis->ntics;i++)
!       axis->ticvalues[i] = ffix(fmin + i*axis->ticInterval);
    }
      
    else {
*** /tmp/RCSAa24399	Mon Apr  8 10:42:26 1991
--- ContourPlot.c	Thu Mar 21 11:05:48 1991
***************
*** 1,4 ****
! /* $Header: /local/src/AtPlotter/RCS/ContourPlot.c,v 1.1 1991/03/21
17:41:27 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
--- 1,4 ----
! /* $Header: /local/src/AtPlotter/RCS/ContourPlot.c,v 1.2 1991/03/21
18:05:06 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
***************
*** 248,254 ****
      new->contourplot.valid = False;
      xchanged = True;
      if (new->contourplot.xPoints != NULL)
!       XtRealloc(new->contourplot.xpts, 
  		new->contourplot.xNumPoints * sizeof(double));
      else  {
        XtFree(new->contourplot.xpts);
--- 248,254 ----
      new->contourplot.valid = False;
      xchanged = True;
      if (new->contourplot.xPoints != NULL)
!       new->contourplot.xpts = (double *) XtRealloc(new->contourplot.xpts, 
  		new->contourplot.xNumPoints * sizeof(double));
      else  {
        XtFree(new->contourplot.xpts);
***************
*** 259,265 ****
      new->contourplot.valid = False;
      ychanged = True;
      if (new->contourplot.yPoints != NULL)
!       XtRealloc(new->contourplot.ypts, 
  		new->contourplot.yNumPoints * sizeof(double));
      else  {
        XtFree(new->contourplot.ypts);
--- 259,265 ----
      new->contourplot.valid = False;
      ychanged = True;
      if (new->contourplot.yPoints != NULL)
!       new->contourplot.ypts  = (double *) XtRealloc(new->contourplot.ypts, 
  		new->contourplot.yNumPoints * sizeof(double));
      else  {
        XtFree(new->contourplot.ypts);
***************
*** 281,287 ****
    }
  
    if (Changed(xNumPoints) || Changed(yNumPoints))  {
!     XtRealloc(new->contourplot.zpts, new->contourplot.xNumPoints *
  	      new->contourplot.yNumPoints * sizeof(double));
      bcopy((char *) new->contourplot.zPoints, new->contourplot.zpts,
  	  new->contourplot.xNumPoints * sizeof(double) * 
--- 281,288 ----
    }
  
    if (Changed(xNumPoints) || Changed(yNumPoints))  {
!     new->contourplot.zpts = (double *) XtRealloc(new->contourplot.zpts,
! 	 new->contourplot.xNumPoints *
  	      new->contourplot.yNumPoints * sizeof(double));
      bcopy((char *) new->contourplot.zPoints, new->contourplot.zpts,
  	  new->contourplot.xNumPoints * sizeof(double) * 
*** /tmp/RCSAa24399	Mon Apr  8 10:42:28 1991
--- FBarchart.c	Thu Mar 21 11:05:50 1991
***************
*** 1,4 ****
! /* $Header: /local/src/AtPlotter/RCS/FBarchart.c,v 1.1 1991/03/21
17:41:27 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
--- 1,4 ----
! /* $Header: /local/src/AtPlotter/RCS/FBarchart.c,v 1.2 1991/03/21
18:05:06 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
***************
*** 173,179 ****
    if (bcw->fbarchart.firsttime)
      bcw->fbarchart.y = (double *)XtMalloc(sizeof(double) * nump);
    else 
!     XtRealloc (bcw->fbarchart.y, sizeof(double) * nump);
  
    f = fopen(bcw->fbarchart.dataFile, "r");
    if (f == NULL) {
--- 173,180 ----
    if (bcw->fbarchart.firsttime)
      bcw->fbarchart.y = (double *)XtMalloc(sizeof(double) * nump);
    else 
!     bcw->fbarchart.y =  (double *)
! 	XtRealloc (bcw->fbarchart.y, sizeof(double) * nump);
  
    f = fopen(bcw->fbarchart.dataFile, "r");
    if (f == NULL) {
No differences encountered
*** /tmp/RCSAa24399	Mon Apr  8 10:42:33 1991
--- Scale.c	Tue Mar 26 18:28:23 1991
***************
*** 1,4 ****
! /* $Header: /local/src/AtPlotter/RCS/Scale.c,v 1.1 1991/03/21
21:40:09 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
--- 1,4 ----
! /* $Header: /net/stout/local/src/AtPlotter/RCS/Scale.c,v 1.2 91/03/26
18:27:45 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
***************
*** 46,58 ****
  {
    s->errorcode = SCALEERROR_NONE;
  
    if (s->high < s->low) {
      s->errorcode = SCALEERROR_BOUNDLESS;
      s->transform = AtTransformINVALID;
      return;
    }
  
!   if (s->high - s->low < _AtScaleAlmostZero) {
      s->errorcode = SCALEERROR_BOUNDCLOSE;
      s->transform = AtTransformINVALID;
      return;
--- 46,60 ----
  {
    s->errorcode = SCALEERROR_NONE;
  
+ #ifdef NOTDEF
    if (s->high < s->low) {
      s->errorcode = SCALEERROR_BOUNDLESS;
      s->transform = AtTransformINVALID;
      return;
    }
+ #endif
  
!   if ( fabs(s->high - s->low) < _AtScaleAlmostZero) {
      s->errorcode = SCALEERROR_BOUNDCLOSE;
      s->transform = AtTransformINVALID;
      return;
*** /tmp/RCSAa24399	Mon Apr  8 10:42:36 1991
--- XYErrorPlot.c	Thu Mar 21 11:05:52 1991
***************
*** 1,4 ****
! /* $Header: /local/src/AtPlotter/RCS/XYErrorPlot.c,v 1.1 1991/03/21
17:41:27 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
--- 1,4 ----
! /* $Header: /local/src/AtPlotter/RCS/XYErrorPlot.c,v 1.2 1991/03/21
18:05:06 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
***************
*** 264,280 ****
    /* Need to check XYPlot's numPoints resource, because if it changed,
       we have to resize the error arrays and reread them. */
    if (current->xyplot.numPoints != new->xyplot.numPoints)  {
!     XtRealloc(new->xyerrorplot.errabove, new->xyplot.numPoints * 
  	      sizeof(double));
!     XtRealloc(new->xyerrorplot.errbelow, new->xyplot.numPoints * 
  	      sizeof(double));
!     XtRealloc(new->xyerrorplot.abovepts, new->xyplot.numPoints * 
  	      sizeof(double));
!     XtRealloc(new->xyerrorplot.belowpts, new->xyplot.numPoints * 
  	      sizeof(double));
!     XtRealloc(new->xyerrorplot.abovepix, new->xyplot.numPoints * 
  	      sizeof(XPoint));
!     XtRealloc(new->xyerrorplot.belowpix, new->xyplot.numPoints * 
  	      sizeof(XPoint));
      abovechanged = belowchanged = True;
    }
--- 264,286 ----
    /* Need to check XYPlot's numPoints resource, because if it changed,
       we have to resize the error arrays and reread them. */
    if (current->xyplot.numPoints != new->xyplot.numPoints)  {
!     new->xyerrorplot.errabove = (double *)
! 	XtRealloc(new->xyerrorplot.errabove, new->xyplot.numPoints * 
  	      sizeof(double));
!     new->xyerrorplot.errbelow =  (double *)
! 	XtRealloc(new->xyerrorplot.errbelow, new->xyplot.numPoints * 
  	      sizeof(double));
!     new->xyerrorplot.abovepts = (double *)
! 	XtRealloc(new->xyerrorplot.abovepts, new->xyplot.numPoints * 
  	      sizeof(double));
!     new->xyerrorplot.belowpts = (double *)
! 	XtRealloc(new->xyerrorplot.belowpts, new->xyplot.numPoints * 
  	      sizeof(double));
!     new->xyerrorplot.abovepix =  (XPoint *)
! 	XtRealloc(new->xyerrorplot.abovepix, new->xyplot.numPoints * 
  	      sizeof(XPoint));
!     new->xyerrorplot.belowpix = (XPoint *)
! 	XtRealloc(new->xyerrorplot.belowpix, new->xyplot.numPoints * 
  	      sizeof(XPoint));
      abovechanged = belowchanged = True;
    }
*** /tmp/RCSAa24399	Mon Apr  8 10:42:39 1991
--- XYPlot.c	Thu Mar 21 11:05:55 1991
***************
*** 1,4 ****
! /* $Header: /local/src/AtPlotter/RCS/XYPlot.c,v 1.1 1991/03/21
17:41:27 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
--- 1,4 ----
! /* $Header: /local/src/AtPlotter/RCS/XYPlot.c,v 1.2 1991/03/21
18:05:06 vanandel Exp $ */
  
  /*******************************************************************
    Copyright (C) 1990 by the Massachusetts Institute of Technology
***************
*** 290,299 ****
      new->plot.redisplay = True;
  
    if (Changed(numPoints)) {
!     XtRealloc(NEW.xpts, sizeof(double)*new->xyplot.numPoints);
!     XtRealloc(NEW.ypts, sizeof(double)*new->xyplot.numPoints);
!     XtRealloc(NEW.pixpts, sizeof(XPoint)*new->xyplot.numPoints);
!     XtRealloc(NEW.oldpixpts, sizeof(XPoint)*new->xyplot.numPoints);
  
      bcopy(NEW.xPoints, NEW.xpts, sizeof(double) * NEW.numPoints);
      bcopy(NEW.yPoints, NEW.ypts, sizeof(double) * NEW.numPoints);
--- 290,299 ----
      new->plot.redisplay = True;
  
    if (Changed(numPoints)) {
!     NEW.xpts = (double *)XtRealloc(NEW.xpts,
sizeof(double)*new->xyplot.numPoints);
!     NEW.ypts = (double *)XtRealloc(NEW.ypts,
sizeof(double)*new->xyplot.numPoints);
!     NEW.pixpts = (XPoint *)XtRealloc(NEW.pixpts,
sizeof(XPoint)*new->xyplot.numPoints);
!     NEW.oldpixpts = (XPoint *)XtRealloc(NEW.oldpixpts,
sizeof(XPoint)*new->xyplot.numPoints);
  
      bcopy(NEW.xPoints, NEW.xpts, sizeof(double) * NEW.numPoints);
      bcopy(NEW.yPoints, NEW.ypts, sizeof(double) * NEW.numPoints);

	Joe VanAndel  		Internet:vanandel@ncar.ucar.edu
	NCAR / RSF  			
	P.O Box 3000		Fax:	 303-497-2044
	Boulder, CO 80307-3000	Voice:	 303-497-2071 
