| T.R | Title | User | Personal Name
 | Date | Lines | 
|---|
| 294.1 |  | AUSS::BELL | Caritas Patiens est | Wed Mar 12 1997 14:38 | 6 | 
|  |     I'd have a close look at what was happening on line 35 for bk.c
    
    It looks like it is writing to a location that has just been released
    by a call to realloc.
    
Peter.
 | 
| 294.2 | Suggestions? | SMURF::JPW | John P Williams, DUDE, USG, 381-2079 | Thu Mar 13 1997 05:53 | 6 | 
|  | The answer in .1 sounds correct. To help us improve the Third Degree tool,
could anyone suggest a way in which we could make the error clearer, or
could the customer tell us what it is about the error message that makes
it difficult to understand?
		Thanks
 | 
| 294.3 | lhs static pointer?!?!? | RHETT::HALETKY |  | Mon Mar 17 1997 09:36 | 9 | 
|  |     What I don't understand then is how this can be true with the code
    provided. This implies that the lhs of the realloc is set before the
    call to realloc and that the lhs can never change.
    
    This does not seem possible to me.
    
    Best regards,
    Ed Haletky
    Digital CSC
 | 
| 294.4 |  | AUSS::BELL | Caritas Patiens est | Mon Mar 17 1997 13:26 | 4 | 
|  |     Can you include the code in a note here?
    
Peter.
    
 | 
| 294.5 | The Source | RHETT::HALETKY |  | Wed Mar 19 1997 09:08 | 71 | 
|  |     #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    typedef struct tSampleObj
    {       long            Left;
            long            Right;
            long            Prev;
    }t_SampleObj;
    
    t_SampleObj             *SampleObj = NULL;
    long                    nSampleObjs = 0;
    long                    iSampleObj;
    
    #define bSAMPLEOBJ      1000
    #define sSAMPLEOBJ      sizeof(t_SampleObj)
    #define pSAMPLEOBJ      (t_SampleObj *)
    #define SAMPLEOBJ       SampleObj[iSampleObj]
    #define NullFld(s, n) memset((char *) s, '\0', n)
    
    long    NxtSampleObj();
    
    int main()
    {
    int             i;
    
            iSampleObj = NxtSampleObj();
    
            for (i = 0; i < 3000; i++)
            {
    /* if the call to NxtSampleObj() causes realloc
       assignment is to address of memory freed by realloc
       why is the address of SAMPLEOBJ fixed before the call to
    NxtSampleObj() ????
    */
                    SAMPLEOBJ.Left  = NxtSampleObj();
                    SAMPLEOBJ.Right = -1;
                    SAMPLEOBJ.Prev  = -1;
                    iSampleObj = SAMPLEOBJ.Left;
            }
            return 0;
    }
    long NxtSampleObj()
    {
    static int    mSampleObjs = 0;
    
        nSampleObjs++;
        if (nSampleObjs >= mSampleObjs)
        {
            mSampleObjs += bSAMPLEOBJ;
    
            if (!SampleObj)
                SampleObj = (t_SampleObj *) calloc(mSampleObjs,
    sSAMPLEOBJ);
            else
                SampleObj = (t_SampleObj *) realloc(SampleObj, mSampleObjs
    * sSAMPLE
    OBJ);
    
            if (!SampleObj)
            {
                fprintf(stderr, "NxtSampleObj - Unable To Allocate");
                perror("NxtSampleObj");
                exit(1);
            }
            NullFld(&SampleObj[mSampleObjs - bSAMPLEOBJ], bSAMPLEOBJ *
    sSAMPLEOBJ);
        }
        return (nSampleObjs - 1);
    }
    
 | 
| 294.6 | Compiler can rearrange order of evaluation of expressions | SMURF::JPW | John P Williams, DUDE, USG, 381-2079 | Thu Mar 20 1997 08:25 | 14 | 
|  | I added a local variable "long next;" and split line 35 into two parts:
<                 SAMPLEOBJ.Left  = NxtSampleObj();
---
>                 nxt  = NxtSampleObj();
>                 SAMPLEOBJ.Left  = nxt;
This made the Third Degree warning go away.
I figure the reason is that a C compiler is allowed to rearrange the 
order in which an expression is evaluated. Assignment is an expression 
in C, so the compiler is allowed to evaluate the left hand side before
the right hand side, which in this case changes the left hand side.
That is, the program is erroneous.
 |