Пример #1
0
static void *sqlite3MemRealloc(void *pPrior, int nByte){
  int *pOld = ((int *)pPrior) - 1, szOld = *pOld;
  void *pNew;

  if( nByte <= szOld ){
    return pPrior;
  } else {
    pNew = sqlite3MemMalloc(nByte);
    if (!pNew) return 0;
    memcpy(pNew, pPrior, szOld);
    sqlite3MemFree(pPrior);
    return pNew;
  }
}
Пример #2
0
/*
** Change the size of an existing memory allocation.
**
** For this debugging implementation, we *always* make a copy of the
** allocation into a new place in memory.  In this way, if the 
** higher level code is using pointer to the old allocation, it is 
** much more likely to break and we are much more liking to find
** the error.
*/
static void *sqlite3MemRealloc(void *pPrior, int nByte){
  struct MemBlockHdr *pOldHdr;
  void *pNew;
  assert( mem.disallow==0 );
  pOldHdr = sqlite3MemsysGetHeader(pPrior);
  pNew = sqlite3MemMalloc(nByte);
  if( pNew ){
    memcpy(pNew, pPrior, nByte<pOldHdr->iSize ? nByte : pOldHdr->iSize);
    if( nByte>pOldHdr->iSize ){
      memset(&((char*)pNew)[pOldHdr->iSize], 0x2b, nByte - pOldHdr->iSize);
    }
    sqlite3MemFree(pPrior);
  }
  return pNew;
}