MySQL: Fix off-by-one in allocation and pass address of correct bind result buffer to mysql_stmt_fetch_column() default tip

Sat, 30 Jun 2012 00:37:19 +0200

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 30 Jun 2012 00:37:19 +0200
changeset 46
5ba1dd988961
parent 45
7c968f66bccd

MySQL: Fix off-by-one in allocation and pass address of correct bind result buffer to mysql_stmt_fetch_column()

dbd/mysql/statement.c file | annotate | diff | comparison | revisions
--- a/dbd/mysql/statement.c	Fri Jun 29 17:45:37 2012 +0100
+++ b/dbd/mysql/statement.c	Sat Jun 30 00:37:19 2012 +0200
@@ -346,12 +346,10 @@
 		const char *name = fields[i].name;
 
 		if (bind[i].buffer == NULL) {
-		    char *buffer = (char *)malloc(real_length[i]);
-		    memset(buffer, 0, real_length[i]);
-
+		    char *buffer = (char *)calloc(real_length[i]+1, sizeof(char));
 		    bind[i].buffer = buffer;
 		    bind[i].buffer_length = real_length[i];
-		    mysql_stmt_fetch_column(statement->stmt, bind, i, 0);
+		    mysql_stmt_fetch_column(statement->stmt, &bind[i], i, 0);
 		}
 
 		if (lua_push == LUA_PUSH_NIL) {

mercurial