> From: Alberto Monteiro <[EMAIL PROTECTED]>

> I think I found a possible problem.
> 
> Let´s suppose that PutAt * IntSize is exactly equal to CurrentSize:
> 
> > int IMem::PutInt(const    long PutAt, const int          PutMe)
> > {
> >   if ((PutAt * __Int_Size__) <= CurrentSize)
> 
> It´s true here
> 
> >   {
> >     try //
> >     {
> >       *((int *) &Mem[PutAt * __Int_Size__])       = PutMe;
> 
> Oops. Mem[x] is valid from 0 to CurrentSize - 1, and here
> you are writing to Mem[CurrentSize]. Evil Fool, don´t do it!

Actaully Mem[x] is valid from 0 to MemSize - 1, which should be
>= currentsize.  Which should have been obvious from that big
 post I sent with the entire unfinished class so far.

So in other words I should do something like this:

IMem::IMem(const long AllocBytes)    // default constructor
     {
     CurrentSize            = 0;
     MemSize                = 0;
     Mem                    = NULL;
     temp                   = NULL;
     
     try //
         {
         if (AllocBytes <= __LoMemBlock__)
            {
            MemSize         = __LoMemBlock__;
            }
         else // >__LoMemBlock__
              {
              i             = (AllocBytes / __HiMemBlock__) + 1;
              MemSize       = i * __HiMemBlock__;
              
              while (MemSize < AllocBytes)
                    {
                    i++;
                    MemSize = i * __HiMemBlock__;
                    }
              }
         CurrentSize        = AllocBytes;
         Mem                = new BYTE[MemSize + 1];
                            // ALBERTOS Change ^^^
         }
     catch (...)
           {
           delete [] Mem;
           Mem              = NULL;
           CurrentSize      = 0;
           MemSize          = 0;
           Enterprise();
           MessageBox(hiwind,"IMem Constructor Threw an Exception,"REALLY 
bad",MB_OK);
           // Call Panic Save HERE
           Excelsior();
           throw;
           }
     }

_______________________________________________
http://www.mccmedia.com/mailman/listinfo/brin-l

Reply via email to