1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

CONC-387 return MYSQL_DATA_TRUNCATED for invalid numeric strings.

Fix a regression in new my_atoll()/my_atoull()
to set error, if there are non-digits found in the string.

Spaces at the start and end of string are ignored (however, not between the
digits).
This commit is contained in:
Vladislav Vaintroub
2018-12-07 17:21:18 +01:00
parent 6e59920b6e
commit 1ecc37f94f
2 changed files with 76 additions and 0 deletions

View File

@@ -209,6 +209,7 @@ static long long my_strtoll(const char *str, size_t len, const char **end, int *
return -1LL * uval;
}
static long long my_atoll(const char *str, const char *end_str, int *error)
{
const char *p=str;
@@ -216,18 +217,36 @@ static long long my_atoll(const char *str, const char *end_str, int *error)
long long ret;
while (p < end_str && isspace(*p))
p++;
ret = my_strtoll(p, end_str - p, &end, error);
while(end < end_str && isspace(*end))
end++;
if(end != end_str)
*error= 1;
return ret;
}
static unsigned long long my_atoull(const char *str, const char *end_str, int *error)
{
const char *p = str;
const char *end;
unsigned long long ret;
while (p < end_str && isspace(*p))
p++;
ret = my_strtoull(p, end_str - p, &end, error);
while(end < end_str && isspace(*end))
end++;
if(end != end_str)
*error= 1;
return ret;
}