Browse code

- buffer size increased to 1024 - fixed zero termination of truncated fields (reported by Miklos)

Jan Janak authored on 15/05/2008 10:51:19
Showing 1 changed files
... ...
@@ -52,7 +52,7 @@
52 52
 #include <mysql/errmsg.h>
53 53
 #include <mysql/mysqld_error.h>
54 54
 
55
-#define STR_BUF_SIZE 256
55
+#define STR_BUF_SIZE 1024
56 56
 
57 57
 #ifdef MYSQL_FAKE_NULL
58 58
 
... ...
@@ -604,7 +604,14 @@ static inline int update_result(db_fld_t* result, MYSQL_STMT* st)
604 604
 			break;
605 605
 
606 606
 		case DB_CSTR:
607
-			result[i].v.cstr[rp->length] = '\0';
607
+			if (rp->length < STR_BUF_SIZE) {
608
+				result[i].v.cstr[rp->length] = '\0';
609
+			} else {
610
+				/* Truncated field but rp->length contains full size,
611
+				 * zero terminated the last byte in the buffer
612
+				 */
613
+				result[i].v.cstr[STR_BUF_SIZE - 1] = '\0';
614
+			}
608 615
 #ifdef MYSQL_FAKE_NULL
609 616
 			if (strcmp(FAKE_NULL_STR.s,result[i].v.cstr)==0) {
610 617
 				result[i].flags |= DB_NULL;