Skip to content

Commit 1db2980

Browse files
author
D. Richard Hipp
committed
Use the 64-bit memory allocator interfaces in extensions, whenever possible.
1 parent 252913b commit 1db2980

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

ext/fts3/fts3_snippet.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ struct StrBuffer {
130130
*/
131131
static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
132132
MatchinfoBuffer *pRet;
133-
int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
134-
int nStr = (int)strlen(zMatchinfo);
133+
sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
134+
+ sizeof(MatchinfoBuffer);
135+
sqlite3_int64 nStr = strlen(zMatchinfo);
135136

136-
pRet = sqlite3_malloc(nByte + nStr+1);
137+
pRet = sqlite3_malloc64(nByte + nStr+1);
137138
if( pRet ){
138139
memset(pRet, 0, nByte);
139140
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;

ext/fts3/fts3_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ static int testTokenizerNext(
448448
}else{
449449
/* Advance to the end of the token */
450450
const char *pToken = p;
451-
int nToken;
451+
sqlite3_int64 nToken;
452452
while( p<pEnd && testIsTokenChar(*p) ) p++;
453-
nToken = (int)(p-pToken);
453+
nToken = (sqlite3_int64)(p-pToken);
454454

455455
/* Copy the token into the buffer */
456456
if( nToken>pCsr->nBuffer ){
457457
sqlite3_free(pCsr->aBuffer);
458-
pCsr->aBuffer = sqlite3_malloc(nToken);
458+
pCsr->aBuffer = sqlite3_malloc64(nToken);
459459
}
460460
if( pCsr->aBuffer==0 ){
461461
rc = SQLITE_NOMEM;

ext/fts3/fts3_tokenize_vtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static int fts3tokFilterMethod(
346346
if( idxNum==1 ){
347347
const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
348348
int nByte = sqlite3_value_bytes(apVal[0]);
349-
pCsr->zInput = sqlite3_malloc(nByte+1);
349+
pCsr->zInput = sqlite3_malloc64(nByte+1);
350350
if( pCsr->zInput==0 ){
351351
rc = SQLITE_NOMEM;
352352
}else{

ext/fts3/fts3_tokenizer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ int sqlite3Fts3InitTokenizer(
196196
int iArg = 0;
197197
z = &z[n+1];
198198
while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
199-
int nNew = sizeof(char *)*(iArg+1);
200-
char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
199+
sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
200+
char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
201201
if( !aNew ){
202202
sqlite3_free(zCopy);
203203
sqlite3_free((void *)aArg);

ext/fts3/fts3_write.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,8 +1752,9 @@ int sqlite3Fts3SegReaderPending(
17521752
}
17531753

17541754
if( nElem>0 ){
1755-
int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
1756-
pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
1755+
sqlite3_int64 nByte;
1756+
nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
1757+
pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
17571758
if( !pReader ){
17581759
rc = SQLITE_NOMEM;
17591760
}else{
@@ -3367,7 +3368,7 @@ static void fts3InsertDocsize(
33673368
int rc; /* Result code from subfunctions */
33683369

33693370
if( *pRC ) return;
3370-
pBlob = sqlite3_malloc( 10*p->nColumn );
3371+
pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
33713372
if( pBlob==0 ){
33723373
*pRC = SQLITE_NOMEM;
33733374
return;
@@ -3417,7 +3418,7 @@ static void fts3UpdateDocTotals(
34173418
const int nStat = p->nColumn+2;
34183419

34193420
if( *pRC ) return;
3420-
a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
3421+
a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
34213422
if( a==0 ){
34223423
*pRC = SQLITE_NOMEM;
34233424
return;
@@ -3538,8 +3539,8 @@ static int fts3DoRebuild(Fts3Table *p){
35383539
}
35393540

35403541
if( rc==SQLITE_OK ){
3541-
int nByte = sizeof(u32) * (p->nColumn+1)*3;
3542-
aSz = (u32 *)sqlite3_malloc(nByte);
3542+
sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
3543+
aSz = (u32 *)sqlite3_malloc64(nByte);
35433544
if( aSz==0 ){
35443545
rc = SQLITE_NOMEM;
35453546
}else{
@@ -3605,12 +3606,12 @@ static int fts3IncrmergeCsr(
36053606
){
36063607
int rc; /* Return Code */
36073608
sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
3608-
int nByte; /* Bytes allocated at pCsr->apSegment[] */
3609+
sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */
36093610

36103611
/* Allocate space for the Fts3MultiSegReader.aCsr[] array */
36113612
memset(pCsr, 0, sizeof(*pCsr));
36123613
nByte = sizeof(Fts3SegReader *) * nSeg;
3613-
pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
3614+
pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);
36143615

36153616
if( pCsr->apSegment==0 ){
36163617
rc = SQLITE_NOMEM;
@@ -5590,7 +5591,7 @@ int sqlite3Fts3UpdateMethod(
55905591
}
55915592

55925593
/* Allocate space to hold the change in document sizes */
5593-
aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
5594+
aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
55945595
if( aSzDel==0 ){
55955596
rc = SQLITE_NOMEM;
55965597
goto update_out;

ext/fts5/fts5_tokenize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static int fts5UnicodeCreate(
369369

370370
p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
371371
p->nFold = 64;
372-
p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
372+
p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
373373
if( p->aFold==0 ){
374374
rc = SQLITE_NOMEM;
375375
}

ext/rtree/geopoly.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static GeoPoly *geopolyParseJson(const unsigned char *z, int *pRc){
269269
GeoPoly *pOut;
270270
int x = 1;
271271
s.nVertex--; /* Remove the redundant vertex at the end */
272-
pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
272+
pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
273273
x = 1;
274274
if( pOut==0 ) goto parse_json_err;
275275
pOut->nVertex = s.nVertex;
@@ -655,7 +655,7 @@ static GeoPoly *geopolyBBox(
655655
if( pRc ) *pRc = SQLITE_OK;
656656
if( aCoord==0 ){
657657
geopolyBboxFill:
658-
pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
658+
pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
659659
if( pOut==0 ){
660660
sqlite3_free(p);
661661
if( context ) sqlite3_result_error_nomem(context);
@@ -1051,9 +1051,9 @@ static GeoSegment *geopolySortSegmentsByYAndC(GeoSegment *pList){
10511051
** Determine the overlap between two polygons
10521052
*/
10531053
static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
1054-
int nVertex = p1->nVertex + p2->nVertex + 2;
1054+
sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
10551055
GeoOverlap *p;
1056-
int nByte;
1056+
sqlite3_int64 nByte;
10571057
GeoEvent *pThisEvent;
10581058
double rX;
10591059
int rc = 0;
@@ -1065,7 +1065,7 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
10651065
nByte = sizeof(GeoEvent)*nVertex*2
10661066
+ sizeof(GeoSegment)*nVertex
10671067
+ sizeof(GeoOverlap);
1068-
p = sqlite3_malloc( nByte );
1068+
p = sqlite3_malloc64( nByte );
10691069
if( p==0 ) return -1;
10701070
p->aEvent = (GeoEvent*)&p[1];
10711071
p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
@@ -1224,18 +1224,18 @@ static int geopolyInit(
12241224
){
12251225
int rc = SQLITE_OK;
12261226
Rtree *pRtree;
1227-
int nDb; /* Length of string argv[1] */
1228-
int nName; /* Length of string argv[2] */
1227+
sqlite3_int64 nDb; /* Length of string argv[1] */
1228+
sqlite3_int64 nName; /* Length of string argv[2] */
12291229
sqlite3_str *pSql;
12301230
char *zSql;
12311231
int ii;
12321232

12331233
sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
12341234

12351235
/* Allocate the sqlite3_vtab structure */
1236-
nDb = (int)strlen(argv[1]);
1237-
nName = (int)strlen(argv[2]);
1238-
pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
1236+
nDb = strlen(argv[1]);
1237+
nName = strlen(argv[2]);
1238+
pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
12391239
if( !pRtree ){
12401240
return SQLITE_NOMEM;
12411241
}

0 commit comments

Comments
 (0)