From: dir@lookout.IT.USwc.USwest.COM (Daniel I. Rosenblatt)
Newsgroups: gnu.gcc.bug
Subject: gcc 2.2.2 w/-O4 corrupts diff-1.15
Date: 25 Aug 92 04:31:18 GMT
Distribution: gnu
Organization: GNUs Not Usenet

I've got a Sun 4/670 running SunOS 4.1.2
gcc 2.2.2 was built with 'configure sparc'.
Compiling diff-1.15 with gcc 2.2.2 and -O4 will, with certain input files to
diff, cause diff to core dump.  Recompiling the module analyze.c without
optimization or with only simple optimization (-O) corrects the problem.  Here
is a terminal session showing the problem (including the diff input files):
----------------------------------------------------------------------
Script started on Tue Aug 25 10:19:30 1992
kmongo_jr% gdiff x y >/dev/null
kmongo_jr% bdiff x y >/dev/null
Segmentation fault (core dumped)
kmongo_jr% gdb bdiff core
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
Core was generated by `bdiff'.
Program terminated with signal 11, Segmentation fault.
#0  0x38f4 in diag (xoff=7, xlim=22, yoff=7, ylim=26, cost=0xf7fff7dc)
    at analyze.c:93
93	  bd[bmid] = xlim;
(gdb) where
#0  0x38f4 in diag (xoff=7, xlim=22, yoff=7, ylim=26, cost=0xf7fff7dc)
    at analyze.c:93
#1  0x3fdc in compareseq (xoff=7, xlim=22, yoff=7, ylim=26) at analyze.c:266
#2  0x401c in compareseq (xoff=7, xlim=73, yoff=7, ylim=82) at analyze.c:289
#3  0x4b50 in diff_2_files (filevec=0xf7fff970, depth=0) at analyze.c:792
#4  0x37a8 in compare_files (dir0=0x0, name0=0xf7fffbee "x", dir1=0x0, 
    name1=0xf7fffbf0 "y", depth=0) at diff.c:664
#5  0x2c54 in main (argc=3, argv=0xf7fffb9c) at diff.c:392
(gdb) quit
kmongo_jr% cat x
int MRHierarchyMgr::GetNextPage( MRPageReqPtr curPageInfo )
{
   int           retVal = FALSE;               /* return value */
   long          lastPage = -1,                /* last page of file */
                 nextFile = -1,                /* id of next file in order */
		 nextFileView = -1,            /* if of view for nextFile */
		 nextFileDoc = -1;             /* id of doc for nextFile */
   
      {
      /* get the sequence number of the last page in the cur page's file */
      if( ( lastPage = GetFileLastPageNum( curTocParent, curPageInfo->fileId, 
   		         curPageInfo->docId ) ) == -1 )
         LogError( "GetFileLastPageNum failed in MRHierarchyMgr::GetNextPage",
   	        NULL, 0, USER_ERROR );      
         
      /* if at end of file, find the next file */
      else if( ( ( curPageInfo->pageSeq + 1 ) > lastPage ) &&
               !FindNextFile( curTocParent, curPageInfo->fileId, 
                              curPageInfo->docId, curPageInfo->viewId,
                              &nextFile, &nextFileDoc, &nextFileView ) )
         LogError( "FindNextFile failed in MRHierarchyMgr::GetNextPage",
                   NULL, 0, USER_ERROR );      
         
      /* get the next page if there is one */
      else
         {
         /* at end of file and no more files, tell the gui */
         if( ( ( curPageInfo->pageSeq + 1 ) > lastPage ) && 
             ( nextFile == -1 ) )
            {
            if( !AsyncSendToObjs( DMPMSG_OBJ_TO_OBJ_MSG, 
                                  DMPMSG_NUM_NO_MORE_PAGES, 
    	      	                  (void *)NULL, 0 ) )
               LogError( "AsyncSendToObjs failed in MRHierMgr::GetNextPage",
                         NULL, 0, USER_ERROR );
            else
               retVal = TRUE;
   	    }
   
         /* is a page, so get it */
         else
            {
            /* if new file, load the new file and doc into the structure */
            if( ( curPageInfo->pageSeq + 1 ) > lastPage )
               {
   	       curPageInfo->fileId  = nextFile;
   	       curPageInfo->docId   = nextFileDoc;
   	       curPageInfo->viewId  = nextFileView;
   	       curPageInfo->pageSeq = 1;
               }
   	 
            /* if same file, increment sequence */
            else
   	       curPageInfo->pageSeq++;
   
            /* set defaults */
            curPageInfo->rotation   = defaultRotation;
            curPageInfo->scale      = defaultScale;
            curPageInfo->screenWid  = defaultScreenWid;
            curPageInfo->screenHt   = defaultScreenHt;
            curPageInfo->printFlg   = FALSE;
            curPageInfo->hiWords    = NULL;
            curPageInfo->numHiWords = 0;
   
            if( curPageInfo->pagePath )
               {
               delete curPageInfo->pagePath;
               curPageInfo->pagePath = NULL;
               }
   	 
            /* get the toc index for the page & add it to the page structure */
            if( !AddPageTocIndex( curPageInfo ) )
               LogError( "AddPageTocIndex failed in MRHierMgr::GetNextPage",
                         NULL, 0, USER_ERROR );
   	    
            /* add the path to the page */
            else if( !BuildPagePath( curPageInfo ) )
               LogError( "BuildPagePath failed in MRHierMgr::GetNextPage",
                         NULL, 0, USER_ERROR );	 
   
            /* add the descr and get the page */
            else
   	       {
               strncpy( curPageInfo->pageDescr, 
                        mrHierList[ curPageInfo->hierIndex ].
                        toc[ curPageInfo->tocIndex ].descr, 
                        MR_HIER_MAX_STRING_SIZE - 1 );
               curPageInfo->pageDescr[ MR_HIER_MAX_STRING_SIZE - 1 ] = '\0';
         
      	       /* send the page request */
               if( !SendToObjs( DMPMSG_OBJ_TO_OBJ_MSG, DMPMSG_NUM_GET_PAGE, 
                                (void *)curPageInfo, sizeof( MRPageReqRec ), 
   			        FALSE ) )
                  LogError( "SendToObjs failed in MRHierMgr::GetNextPage",
                            NULL, 0, USER_ERROR );
   	    
     	       else
                  retVal = TRUE;
   	    
               }  /*  end else add the descr and get the page */
   	 
   	    }  /*  end else is a page, so get it */
      
         }  /*  end else get the next page if there is one */

      } /* end if the current TOC matches the page requested */

   /* if the current TOC does not match the page's go request it */
   else
       /* end else the current TOC does not match */

   return retVal;
   
}  /*  end GetNextPage  */
kmongo_jr% cat y
int MRHierarchyMgr::GetNextPage( MRPageReqPtr curPageInfo )
{
   char          buf[256];                     /* message buffer for errors */
   int           pagesLeft = 0;                /* number pages actually avail */
   int           error = FALSE;                /* denotes an error in paging */
   int           reqPageOffset = 0;            /* compute page offset to get */
   int           retVal = FALSE;               /* return value */
   long          lastPage = -1,                /* last page of file */
                 nextFile = -1,                /* id of next file in order */
		 nextFileView = -1,            /* id of view for nextFile */
		 nextFileDoc = -1,             /* id of doc for nextFile */
                 rtnNextFile = -1,             /* rtn'd file id */
		 rtnNextFileView = -1,         /* rtn'd view id */
		 rtnNextFileDoc = -1;          /* rtn'd doc id */
   
      {
      /* grab the number of pages requested */
      reqPageOffset = curPageInfo->pageOffset;

      /* get the sequence number of the last page in the cur page's file */
      if( ( lastPage = GetFileLastPageNum( curTocParent, curPageInfo->fileId, 
   		         curPageInfo->docId ) ) == -1 )
         LogError( "GetFileLastPageNum failed in MRHierarchyMgr::GetNextPage",
   	        NULL, 0, USER_ERROR );      

      else 
         {
         /* if the requested page is not in the current file, try to */
         /* page through and find the appropriate file */
         if( ( curPageInfo->pageSeq + reqPageOffset ) > lastPage )
            {
            nextFile = curPageInfo->fileId;
            nextFileDoc = curPageInfo->docId;
            nextFileView = curPageInfo->viewId;
   
            do
               {
               /* if we are on the first file, then subtract off number */
               /* of pages remaining, otherwise subtract number of pages */
               /* in the file */
               if( nextFile == curPageInfo->fileId )
                  {
                  reqPageOffset -= (int) lastPage - curPageInfo->pageSeq;
                  pagesLeft = (int) lastPage - curPageInfo->pageSeq;
                  }
               else
                  {
                  reqPageOffset -=  (int) lastPage;
                  pagesLeft += (int) lastPage;
                  }

               /* go get the next file */
               if( ( !FindNextFile( curTocParent, nextFile, 
                                  nextFileDoc, nextFileView, &rtnNextFile, 
                                  &rtnNextFileDoc, &rtnNextFileView ) ) ||
                   ( rtnNextFile == -1 ) )
                  {
                  error = TRUE;
                  }

               /* find out how many pages in next file */
               else if( ( lastPage = GetFileLastPageNum( curTocParent, 
                                        rtnNextFile, rtnNextFileDoc ) ) == -1 )
                  {
                  error = TRUE;
                  }

               nextFile = rtnNextFile;
               nextFileDoc = rtnNextFileDoc;
               nextFileView = rtnNextFileView;
               }

               /* Add 1 to test for last page in case seq number was a zero. */
               /* If requested page in this file or if there was an error, */
               /* we're done, else keep trying to find the file */
            while( ( reqPageOffset >= lastPage + 1 ) && ( !error ) );

            /* if there was an error (including if there were not enough */
            /* pages to satisfy the request) send a msg and display warning */
            if( error )
               {
               if( !AsyncSendToObjs( DMPMSG_OBJ_TO_OBJ_MSG, 
                                     DMPMSG_NUM_NO_MORE_PAGES, 
                                     (void *)NULL, 0 ) )
                  LogError( "AsyncSendToObjs failed in MRHierMgr::GetNextPage",
                            NULL, 0, USER_ERROR );
               else
                  {
                  if( pagesLeft <= 0 )
                     sprintf( buf, "There are no more pages available.\n" );
                  else if( pagesLeft == 1 )
                     sprintf( buf, "There is only one more page available.\n" );
                  else
                     sprintf( buf, "There are only %d more pages available.\n",
                              pagesLeft );

                  if ( !AsyncSendToObjs( DMPMSG_OBJ_TO_OBJ_MSG,
                                         DMPMSG_NUM_DISPLAY_WARNING,
                                         buf, strlen( buf ) + 1 ) )
                     LogError( "AsyncSendToObjs failed in MRHierMgr::GetNextPg",
                               NULL, 0, USER_ERROR );

                  else 
                     retVal = TRUE;
                  }
               }
            else  
               {
               /* save info about file we want to retrieve the requested page */
               curPageInfo->fileId  = rtnNextFile;
               curPageInfo->docId   = rtnNextFileDoc;
               curPageInfo->viewId  = rtnNextFileView;
               curPageInfo->pageSeq = reqPageOffset;
               }
   	    }
   	 
         /* else the page is in the current file, increment sequence */
         else
            curPageInfo->pageSeq += reqPageOffset;
   
         /* if there were no errors, go make the page request */
         if( !error )
            {
            /* set defaults */
            curPageInfo->rotation   = defaultRotation;
            curPageInfo->scale      = defaultScale;
            curPageInfo->screenWid  = defaultScreenWid;
            curPageInfo->screenHt   = defaultScreenHt;
            curPageInfo->printFlg   = FALSE;
            curPageInfo->hiWords    = NULL;
            curPageInfo->numHiWords = 0;
         
            if( curPageInfo->pagePath )
               {
               delete curPageInfo->pagePath;
               curPageInfo->pagePath = NULL;
               }
   	 
            /* get the toc index for the page & add it to the page structure */
            if( !AddPageTocIndex( curPageInfo ) )
               LogError( "AddPageTocIndex failed in MRHierMgr::GetNextPage",
                         NULL, 0, USER_ERROR );
   	    
            /* add the path to the page */
            else if( !BuildPagePath( curPageInfo ) )
               LogError( "BuildPagePath failed in MRHierMgr::GetNextPage",
                         NULL, 0, USER_ERROR );	 
   
            /* add the descr and get the page */
            else
   	       {
               strncpy( curPageInfo->pageDescr, 
                        mrHierList[ curPageInfo->hierIndex ].
                        toc[ curPageInfo->tocIndex ].descr, 
                        MR_HIER_MAX_STRING_SIZE - 1 );
               curPageInfo->pageDescr[ MR_HIER_MAX_STRING_SIZE - 1 ] = '\0';
         
      	       /* send the page request */
               if( !SendToObjs( DMPMSG_OBJ_TO_OBJ_MSG, DMPMSG_NUM_GET_PAGE, 
                                (void *)curPageInfo, sizeof( MRPageReqRec ), 
   			        FALSE ) )
                  LogError( "SendToObjs failed in MRHierMgr::GetNextPage",
                            NULL, 0, USER_ERROR );
   	    
     	       else
                  retVal = TRUE;
   	    
               }  /*  end else add the descr and get the page */

            } /* if there were no errors */

         } /* we were able to determine end of current file */
 
      } /* end if the current TOC matches the page requested */

   /* if the current TOC does not match the page's go request it */
   else
       /* end else the current TOC does not match */

   return retVal;
   
}  /*  end GetNextPage  */
kmongo_jr% exit
script done on Tue Aug 25 10:24:11 1992


I can be reached at
dir@lookout.uswest.com
303/595-2854
Newsgroups: gnu.gcc.bug