diff --git a/src/protocol/MySQLResult.inl b/src/protocol/MySQLResult.inl index 2a66ffa7..68153fae 100644 --- a/src/protocol/MySQLResult.inl +++ b/src/protocol/MySQLResult.inl @@ -175,10 +175,8 @@ inline int MySQLCell::as_int() const if (!this->is_int()) return 0; - char num[MYSQL_INT_STR_LENGTH + 1]; - memcpy(num, this->data, this->len); - num[this->len] = '\0'; - return atoi(num); + std::string num((char *)this->data, this->len); + return atoi(num.c_str()); } inline bool MySQLCell::is_float() const @@ -191,10 +189,8 @@ inline float MySQLCell::as_float() const if (!this->is_float()) return 0; - char num[MYSQL_FLOAT_STR_LENGTH + 1]; - memcpy(num, this->data, this->len); - num[this->len] = '\0'; - return strtof(num, NULL); + std::string num((char *)this->data, this->len); + return strtof(num.c_str(), NULL); } inline bool MySQLCell::is_double() const @@ -207,10 +203,8 @@ inline double MySQLCell::as_double() const if (!this->is_double()) return 0; - char num[MYSQL_DOUBLE_STR_LENGTH + 1]; - memcpy(num, this->data, this->len); - num[this->len] = '\0'; - return strtod(num, NULL); + std::string num((char *)this->data, this->len); + return strtod(num.c_str(), NULL); } inline bool MySQLCell::is_ulonglong() const @@ -223,10 +217,8 @@ inline unsigned long long MySQLCell::as_ulonglong() const if (!this->is_ulonglong()) return 0; - char num[MYSQL_LONG_STR_LENGTH + 1]; - memcpy(num, this->data, this->len); - num[this->len] = '\0'; - return strtoull(num, NULL, 10); + std::string num((char *)this->data, this->len); + return strtoull(num.c_str(), NULL, 10); } inline bool MySQLCell::is_date() const diff --git a/src/protocol/mysql_types.h b/src/protocol/mysql_types.h index 864cf2fd..6e4ee4a5 100644 --- a/src/protocol/mysql_types.h +++ b/src/protocol/mysql_types.h @@ -22,10 +22,6 @@ #define MYSQL_STATE_LENGTH 5 #define MYSQL_STATE_DEFAULT "HY000" -#define MYSQL_INT_STR_LENGTH 11 // 10 for unsigned int -#define MYSQL_LONG_STR_LENGTH 21 // 20 for unsigned long long -#define MYSQL_FLOAT_STR_LENGTH 7 // 7 for float -#define MYSQL_DOUBLE_STR_LENGTH 19 // 19 for long double // may be set by server in EOF/OK packet #define MYSQL_SERVER_MORE_RESULTS_EXIST 0x0008