You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
Fix for CONC-177: Fixed length calculation for zerofill conversion from
float/double to string
This commit is contained in:
@@ -311,7 +311,7 @@ static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len)
|
|||||||
memcpy(r_param->buffer, start, MIN(copylen, r_param->buffer_length));
|
memcpy(r_param->buffer, start, MIN(copylen, r_param->buffer_length));
|
||||||
}
|
}
|
||||||
if (copylen < r_param->buffer_length)
|
if (copylen < r_param->buffer_length)
|
||||||
((char *)r_param->buffer)[copylen]= '\0';
|
((char *)r_param->buffer)[copylen]= 0;
|
||||||
*r_param->error= (copylen > r_param->buffer_length);
|
*r_param->error= (copylen > r_param->buffer_length);
|
||||||
|
|
||||||
*r_param->length= (ulong)len;
|
*r_param->length= (ulong)len;
|
||||||
@@ -592,9 +592,11 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, fl
|
|||||||
if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1)
|
if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1)
|
||||||
break;
|
break;
|
||||||
ma_bmove_upp(buff + field->length, buff + length, length);
|
ma_bmove_upp(buff + field->length, buff + length, length);
|
||||||
memset((char*) buff, 0, field->length - length);
|
memset((char*) buff, '0', field->length - length);
|
||||||
|
length= field->length;
|
||||||
}
|
}
|
||||||
convert_froma_string(r_param, buff, strlen(buff));
|
|
||||||
|
convert_froma_string(r_param, buff, length);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -689,9 +691,10 @@ static void convert_from_double(MYSQL_BIND *r_param, const MYSQL_FIELD *field, d
|
|||||||
if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1)
|
if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1)
|
||||||
break;
|
break;
|
||||||
ma_bmove_upp(buff + field->length, buff + length, length);
|
ma_bmove_upp(buff + field->length, buff + length, length);
|
||||||
memset((char*) buff, 0, field->length - length);
|
memset((char*) buff, '0', field->length - length);
|
||||||
|
length= field->length;
|
||||||
}
|
}
|
||||||
convert_froma_string(r_param, buff, strlen(buff));
|
convert_froma_string(r_param, buff, length);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -4147,7 +4147,52 @@ static int test_conc167(MYSQL *mysql)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_conc177(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
MYSQL_STMT *stmt;
|
||||||
|
int rc;
|
||||||
|
MYSQL_BIND bind[2];
|
||||||
|
char *stmt_str= "SELECT a,b FROM t1";
|
||||||
|
char buf1[128], buf2[128];
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "CREATE TABLE t1 (a double zerofill default 8.8,b float zerofill default 8.8)");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (DEFAULT, DEFAULT)");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
stmt= mysql_stmt_init(mysql);
|
||||||
|
rc= mysql_stmt_prepare(stmt, stmt_str, strlen(stmt_str));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
memset(bind, 0, 2 * sizeof(MYSQL_BIND));
|
||||||
|
bind[0].buffer= &buf1;
|
||||||
|
bind[0].buffer_type= MYSQL_TYPE_STRING;
|
||||||
|
bind[0].buffer_length= 128;
|
||||||
|
bind[1].buffer= &buf2;
|
||||||
|
bind[1].buffer_type= MYSQL_TYPE_STRING;
|
||||||
|
bind[1].buffer_length= 128;
|
||||||
|
|
||||||
|
rc= mysql_stmt_bind_result(stmt, bind);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_fetch(stmt);
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
diag("buf1 %s\nbuf2 %s", buf1, buf2);
|
||||||
|
|
||||||
|
FAIL_IF(strcmp(buf1, "00000000000000000008.8"), "Expected 00000000000000000008.8");
|
||||||
|
FAIL_IF(strcmp(buf2, "0000000008.8"), "Expected 0000000008.8");
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
|
{"test_conc177", test_conc177, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc167", test_conc167, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc167", test_conc167, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc168", test_conc168, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc168", test_conc168, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc155", test_conc155, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc155", test_conc155, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
|
Reference in New Issue
Block a user