diff options
Diffstat (limited to 'src/func.c')
-rw-r--r-- | src/func.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/func.c b/src/func.c index 893406ceb..673b77e30 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.236 2009/05/28 01:00:55 drh Exp $ +** $Id: func.c,v 1.237 2009/06/03 01:24:54 drh Exp $ */ #include "sqliteInt.h" #include <stdlib.h> @@ -247,7 +247,7 @@ static void substrFunc( static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; - char zBuf[500]; /* larger than the %f representation of the largest double */ + char *zBuf; assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; @@ -257,9 +257,14 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ } if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; r = sqlite3_value_double(argv[0]); - sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r); - sqlite3AtoF(zBuf, &r); - sqlite3_result_double(context, r); + zBuf = sqlite3_mprintf("%.*f",n,r); + if( zBuf==0 ){ + sqlite3_result_error_nomem(context); + }else{ + sqlite3AtoF(zBuf, &r); + sqlite3_free(zBuf); + sqlite3_result_double(context, r); + } } #endif |