# HG changeset patch # User nrich@ii.net # Date 1229817187 0 # Node ID 2cc3feba92771a19c9dc47886d885a343dbc5c6f # Parent abb9499bef517f21525449c34e5c3994b6282c70 Cleanup. diff -r abb9499bef51 -r 2cc3feba9277 dbd/db2/dbd_db2.h --- a/dbd/db2/dbd_db2.h Sat Dec 20 11:17:37 2008 +0000 +++ b/dbd/db2/dbd_db2.h Sat Dec 20 23:53:07 2008 +0000 @@ -41,6 +41,7 @@ typedef struct _statement { resultset_t * resultset; bindparams_t * bind; + unsigned char *buffer; SQLSMALLINT num_result_columns; /* variable for SQLNumResultCols */ SQLHANDLE stmt; diff -r abb9499bef51 -r 2cc3feba9277 dbd/db2/statement.c --- a/dbd/db2/statement.c Sat Dec 20 11:17:37 2008 +0000 +++ b/dbd/db2/statement.c Sat Dec 20 23:53:07 2008 +0000 @@ -1,5 +1,7 @@ #include "dbd_db2.h" +#define BIND_BUFFER_SIZE 1024 + static lua_push_type_t db2_to_lua_push(unsigned int db2_type, int len) { lua_push_type_t lua_type; @@ -80,7 +82,7 @@ int errflag = 0; const char *errstr = NULL; SQLRETURN rc = SQL_SUCCESS; - unsigned char b[1024]; + unsigned char b[BIND_BUFFER_SIZE]; unsigned char *buffer = &b[0]; int offset = 0; resultset_t *resultset = NULL; @@ -118,6 +120,10 @@ return 2; } + if (num_params > (BIND_BUFFER_SIZE/sizeof(double))) { + luaL_error(L, "Too many bind params: %d", num_params); + } + for (p = 2; p <= n; p++) { int i = p - 1; int type = lua_type(L, p); diff -r abb9499bef51 -r 2cc3feba9277 dbd/mysql/statement.c --- a/dbd/mysql/statement.c Sat Dec 20 11:17:37 2008 +0000 +++ b/dbd/mysql/statement.c Sat Dec 20 23:53:07 2008 +0000 @@ -70,8 +70,7 @@ int num_bind_params = n - 1; int expected_params; - unsigned char b[1024]; - unsigned char *buffer = &b[0]; + unsigned char *buffer = NULL; int offset = 0; MYSQL_BIND *bind = NULL; @@ -100,14 +99,16 @@ return 2; } - bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); - - if (bind == NULL) { - luaL_error(L, "Could not alloc bind params\n"); + if (num_bind_params) { + bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); + if (bind == NULL) { + luaL_error(L, "Could not alloc bind params\n"); + } + + buffer = malloc(num_bind_params * sizeof(size_t)); + memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); } - memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); - for (p = 2; p <= n; p++) { int type = lua_type(L, p); int i = p - 2; @@ -190,6 +191,10 @@ free(bind); } + if (buffer) { + free(buffer); + } + if (error_message) { lua_pushboolean(L, 0); lua_pushfstring(L, error_message, errstr ? errstr : mysql_stmt_error(statement->stmt));