Ejemplo n.º 1
0
/* =============================================================================
   Function:		ControlBlock	// lokal //
   Author:		Rammi
   Date:		11/16/1995

   Return:		---
   Parameter:		Bkl	Pos of allocated block (original)
			file	file pos from where initial lib function
				was called

   Purpose:		Control integrity of block

   ============================================================================= */
static void ControlBlock(begin *B, const char *file)
{
  unsigned char *p = (((unsigned char *)B)+START_SPACE);
#if RM_TEST_DEPTH > 0
  int DoAbort = 0;
#endif
  /* === the very beginning === */
  if (B->StpA != PREV_STOP) {
#if RM_TEST_DEPTH > 0
    DoAbort = 1;
#endif
    fprintf(stderr, HEAD
	    "Corrupted block begin (overwritten from elsewhere)\n"
	    "\tshould be: %08x\n"
	    "\tis:        %08x\n"
#ifdef GENERATIONS
	    "\tblock was allocated in %s [%u Bytes, generation %u]\n"
#else
	    "\tblock was allocated in %s [%u Bytes]\n"
#endif
	    "\terror was detected in  %s\n",
	    PREV_STOP,
	    B->StpA,
	    B->File,
	    (unsigned) B->Size,
#ifdef GENERATIONS
	    B->Generation,
#endif
	    file);
  }

  /* === begin of user data === */
  if (B->StpB != PREV_STOP) {
#if RM_TEST_DEPTH > 0
    DoAbort = 1;
#endif
    fprintf(stderr, HEAD
	    "Corrupted block begin (possibly written back)\n"
	    "\tshould be: %08x\n"
	    "\tis:        %08x\n"
#ifdef GENERATIONS
	    "\tblock was allocated in %s [%u Bytes, generation %u]\n"
#else
	    "\tblock was allocated in %s [%u Bytes]\n"
#endif
	    "\terror was detected in  %s\n",
	    PREV_STOP,
	    B->StpB,
	    B->File,
	    (unsigned) B->Size,
#ifdef GENERATIONS
	    B->Generation,
#endif
	    file);
  }

  /* === end of user data === */
  if (memcmp(p+B->Size, &End, END_SPACE) != 0) {
    unsigned char *E = (unsigned char *)(p+B->Size);
    unsigned i;
    int found = 0;
#if RM_TEST_DEPTH > 0
    DoAbort = 1;
#endif
    fprintf(stderr, HEAD
	    "Corrupted block end (possibly written past the end)\n"
	    "\tshould be:");
    for (i = 0;   i < END_SPACE;   i++) {
      fprintf(stderr, i%4 ? "%02x" : " %02x", End[i]);
    }

    fprintf(stderr,
	    "\n\tis:       ");
    for (i = 0;   i < END_SPACE;   i++) {
      fprintf(stderr, i%sizeof(int) ? "%02x" : " %02x", E[i]);
    }
    fprintf(stderr, "\n"
#ifdef GENERATIONS
	    "\tblock was allocated in %s [%u Bytes, generation %u]\n"
#else
	    "\tblock was allocated in %s [%u Bytes]\n"
#endif
	    "\terror was detected in %s\n",
	    B->File,
	    (unsigned) B->Size,
#ifdef GENERATIONS
	    B->Generation,
#endif
	    file
	    );

#if RM_TEST_DEPTH > 0
    if (!((unsigned long)E % sizeof(void *))   &&
	!(*(unsigned long *)E % sizeof(void *))) {  /* because of alignment */
      /* Special service: look if memory was overwritten with pointer */
      if (FindBlk(*(unsigned char **)E)) {
	begin *b = (begin *)((*(unsigned char **)E)-START_SPACE);
	if (IsPossibleFilePos(b->File, b->Size)) {
	  fprintf(stderr,
		  "\tFirst %d bytes of overwritten memory can be interpreted\n"
		  "\t\tas a pointer to a block "
		  " allocated in:\n"
#ifdef GENERATIONS
		  "\t\t%s [%u Bytes, generation %u]\n",
#else
		  "\t\t%s [%u Bytes]\n",
#endif
		  sizeof(void *),
		  b->File,
		  (unsigned) b->Size
#ifdef GENERATIONS
		  , b->Generation
#endif
		  );
	  found = 1;
	}
      }
    }
    if (!found)
#endif
    {
      /* Look, what we can find... */
      int  j;

      for (j = END_SPACE-1;   j >= 0;   j--) {
	if (E[j] != End[j]) {
	  break;
	}
      }
      if (j >= 0   &&   !E[j]) {
	/* Ends with '\0', so it's possibly a string */
	if (j > 0) {
	  while (--j >= 0) {
	    if (!E[j]) {
	      break;
	    }
	  }
	  if (j < 0) {
	    fprintf(stderr,
		    "\tLooks somewhat like a too long string,\n"
		    "\t\tending with \"%s\"\n",
		    E);
	  }
	}
	else {
	  /* Off by one? */
	  fprintf(stderr,
		  "\tLooks like string allocated one byte too short\n"
		  "\t\t(forgetting the nul byte)\n");
	}
      }
    }
  }

#if RM_TEST_DEPTH > 0
  /* Die LOUD */
  if (DoAbort) {
    abort();
  }
#endif
}
Ejemplo n.º 2
0
int cTYVEINF::cXXfirst( //==0:leidis;==POLE_SEDA,POLE_YLDSE:polnud
	const FSxCHAR *stem,
	const int     slen,
	int          *index)
	{
	int tab_idx, ret=0, i;
    const UB1 *ptr;
    if(slen<=0)
        {
        return POLE_YLDSE;
        }
	if ( KOtsi(&ps, stem, slen, &tab_idx) == true )
		{
		// Oli kahendtabelis.
		FindBt(tab_idx, index);
        ret=0;
		}
	else
		{
		// Polnud kahendtabelis.
		ret = FindBlk((tab_idx ? tab_idx - 1 : tab_idx), stem, slen, index);
		}
	if(ret == 0)
		{
        int nS6naLiiki=sonaliik[pre.v_tabidx()]->GetLength();
        //
        //selle koha peal anname tyveinfo tagasi,
        //seda peab sutsu teisendama!
        //
        ptr = (UB1 *)xptr;
        //
        //stem - otsitav t�vi
        //dptr viitab UUS_TYVE_INF struktuurile kettal
        //see tuleb teisendada vana TYVE_INF struktuuri elementideks
        //
        for(i=0; i < nS6naLiiki; i++)
            {
            int tmp;
			dptr[i].piiriKr6nksud = pre.v_piir(); // TV 990312
            tmp = (((int)(ptr[0]))&0xFF) | ( (((int)(ptr[1]))&0xFF)<<8);
            dptr[i].idx.blk_idx = (_uint8)((tmp   )& 0x3F );
            dptr[i].idx.tab_idx = (_int16)((tmp>>6)& 0x3FF);
            switch(nKr6nksuBaiti)
                {
                case 1:
                    dptr[i].lisaKr6nksud=((_int16)(ptr[2]))&0xFF;
                    break;
                case 2:
                    dptr[i].lisaKr6nksud=(_int16)(((unsigned)(ptr[2])) | (((unsigned)(ptr[3])) << 8));
                    break;
                }
            ptr += sizeof(_uint8)+sizeof(_uint8)+nKr6nksuBaiti;
            MKT1c *rec;
            if((rec=tyveMuutused.Get(dptr[i].idx.tab_idx,dptr[i].idx.blk_idx))==NULL)
                {
//printf("%s:%d -- SUUR JAMA\n", __FILE__,__LINE__);
                // vale l�pu # grupis
                throw(VEAD(ERR_MG_MOOTOR,ERR_ROTTEN,__FILE__,__LINE__, "$Revision: 557 $"));
                }
            dptr[i].lg_nr = rec->lgNr;
            }
        }