1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Increased test coverage. Some malloc tests now fail though this is believed

to be an instrumentation problem not a real error. (CVS 2604)

FossilOrigin-Name: f786f37a5e31f42aaf81b3ad4a734f12855da69e
This commit is contained in:
drh
2005-08-20 03:03:04 +00:00
parent 0bbaa1ba9a
commit 85c23c61e2
11 changed files with 231 additions and 39 deletions

View File

@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.142 2005/08/13 18:15:43 drh Exp $
** $Id: util.c,v 1.143 2005/08/20 03:03:04 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -74,13 +74,10 @@ static int memcnt = 0;
#define N_GUARD 2
/*
** Allocate new memory and set it to zero. Return NULL if
** no memory is available.
** Check for a simulated memory allocation failure. Return true if
** the failure should be simulated. Return false to proceed as normal.
*/
void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
void *p;
int *pi;
int i, k;
static int simulatedMallocFailure(int n, char *zFile, int line){
if( sqlite3_iMallocFail>=0 ){
sqlite3_iMallocFail--;
if( sqlite3_iMallocFail==0 ){
@@ -90,10 +87,26 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
n, zFile,line);
#endif
sqlite3_iMallocFail = sqlite3_iMallocReset;
return 0;
return 1;
}
}
if( n==0 ) return 0;
return 0;
}
/*
** Allocate new memory and set it to zero. Return NULL if
** no memory is available.
*/
void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
void *p;
int *pi;
int i, k;
if( n==0 ){
return 0;
}
if( simulatedMallocFailure(n, zFile, line) ){
return 0;
}
sqlite3_memUsed += n;
if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed;
k = (n+sizeof(int)-1)/sizeof(int);
@@ -193,6 +206,9 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
sqlite3Free_(oldP,zFile,line);
return 0;
}
if( simulatedMallocFailure(n, zFile, line) ){
return 0;
}
oldPi = oldP;
oldPi -= N_GUARD+1;
if( oldPi[0]!=0xdead1122 ){