diff options
Diffstat (limited to 'ext/pdo_sqlite/sqlite/src/table.c')
| -rw-r--r-- | ext/pdo_sqlite/sqlite/src/table.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/ext/pdo_sqlite/sqlite/src/table.c b/ext/pdo_sqlite/sqlite/src/table.c index c4e228361f..88a96ee6fd 100644 --- a/ext/pdo_sqlite/sqlite/src/table.c +++ b/ext/pdo_sqlite/sqlite/src/table.c @@ -70,17 +70,15 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){ if( p->nRow==0 ){ p->nColumn = nCol; for(i=0; i<nCol; i++){ - if( colv[i]==0 ){ - z = sqlite3_mprintf(""); - }else{ - z = sqlite3_mprintf("%s", colv[i]); - } + z = sqlite3_mprintf("%s", colv[i]); + if( z==0 ) goto malloc_failed; p->azResult[p->nData++] = z; } }else if( p->nColumn!=nCol ){ - sqlite3SetString(&p->zErrMsg, - "sqlite3_get_table() called with two or more incompatible queries", - (char*)0); + sqlite3_free(p->zErrMsg); + p->zErrMsg = sqlite3_mprintf( + "sqlite3_get_table() called with two or more incompatible queries" + ); p->rc = SQLITE_ERROR; return 1; } @@ -92,9 +90,10 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){ if( argv[i]==0 ){ z = 0; }else{ - z = sqlite3_malloc( strlen(argv[i])+1 ); + int n = strlen(argv[i])+1; + z = sqlite3_malloc( n ); if( z==0 ) goto malloc_failed; - strcpy(z, argv[i]); + memcpy(z, argv[i], n); } p->azResult[p->nData++] = z; } @@ -127,7 +126,7 @@ int sqlite3_get_table( ){ int rc; TabResult res; - if( pazResult==0 ){ return SQLITE_ERROR; } + *pazResult = 0; if( pnColumn ) *pnColumn = 0; if( pnRow ) *pnRow = 0; @@ -138,27 +137,28 @@ int sqlite3_get_table( res.nData = 1; res.nAlloc = 20; res.rc = SQLITE_OK; - res.azResult = sqlite3_malloc( sizeof(char*)*res.nAlloc ); - if( res.azResult==0 ) return SQLITE_NOMEM; + res.azResult = sqlite3_malloc(sizeof(char*)*res.nAlloc ); + if( res.azResult==0 ){ + db->errCode = SQLITE_NOMEM; + return SQLITE_NOMEM; + } res.azResult[0] = 0; rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg); - if( res.azResult ){ - assert( sizeof(res.azResult[0])>= sizeof(res.nData) ); - res.azResult[0] = (char*)res.nData; - } - if( rc==SQLITE_ABORT ){ + assert( sizeof(res.azResult[0])>= sizeof(res.nData) ); + res.azResult[0] = (char*)res.nData; + if( (rc&0xff)==SQLITE_ABORT ){ sqlite3_free_table(&res.azResult[1]); if( res.zErrMsg ){ if( pzErrMsg ){ sqlite3_free(*pzErrMsg); *pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg); } - sqliteFree(res.zErrMsg); + sqlite3_free(res.zErrMsg); } - db->errCode = res.rc; + db->errCode = res.rc; /* Assume 32-bit assignment is atomic */ return res.rc; } - sqliteFree(res.zErrMsg); + sqlite3_free(res.zErrMsg); if( rc!=SQLITE_OK ){ sqlite3_free_table(&res.azResult[1]); return rc; @@ -168,6 +168,7 @@ int sqlite3_get_table( azNew = sqlite3_realloc( res.azResult, sizeof(char*)*(res.nData+1) ); if( azNew==0 ){ sqlite3_free_table(&res.azResult[1]); + db->errCode = SQLITE_NOMEM; return SQLITE_NOMEM; } res.nAlloc = res.nData+1; @@ -188,7 +189,7 @@ void sqlite3_free_table( if( azResult ){ int i, n; azResult--; - if( azResult==0 ) return; + assert( azResult!=0 ); n = (int)azResult[0]; for(i=1; i<n; i++){ if( azResult[i] ) sqlite3_free(azResult[i]); } sqlite3_free(azResult); |
