aboutsummaryrefslogtreecommitdiff
path: root/ext/misc/fileio.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2019-02-27 19:59:56 +0000
committerdrh <drh@noemail.net>2019-02-27 19:59:56 +0000
commit03199343222fdf2db1ee4b264e79e52d251eb483 (patch)
treef8b2de102c866690fe180c8ba72b1886bc33393e /ext/misc/fileio.c
parent89d249364e4cdee732374cfdf2966b17bc3fe44a (diff)
downloadsqlite-03199343222fdf2db1ee4b264e79e52d251eb483.tar.gz
sqlite-03199343222fdf2db1ee4b264e79e52d251eb483.zip
Fix the readfile() UDF so that it returns an empty BLOB, not an OOM error,
when reading an empty file. FossilOrigin-Name: 0edad5339e36d69aed9289bb3e60d35f9930386d76a62bb0194c4fdf420d16fb
Diffstat (limited to 'ext/misc/fileio.c')
-rw-r--r--ext/misc/fileio.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c
index b15e0fda1..255a4fa2e 100644
--- a/ext/misc/fileio.c
+++ b/ext/misc/fileio.c
@@ -152,13 +152,13 @@ static void readFileContents(sqlite3_context *ctx, const char *zName){
fclose(in);
return;
}
- pBuf = sqlite3_malloc64( nIn );
+ pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
if( pBuf==0 ){
sqlite3_result_error_nomem(ctx);
fclose(in);
return;
}
- if( 1==fread(pBuf, nIn, 1, in) ){
+ if( nIn==fread(pBuf, 1, nIn, in) ){
sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
}else{
sqlite3_result_error_code(ctx, SQLITE_IOERR);