Commit 4f9d8270 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

strnto family functions now return error in a new argument

parent 4a77f335
......@@ -138,11 +138,11 @@ typedef struct charset_info_st
int (*longlong10_to_str)(struct charset_info_st *, char *to, uint n, int radix, longlong val);
/* String-to-number convertion routines */
long (*strntol)(struct charset_info_st *, const char *s, uint l,char **e, int base);
ulong (*strntoul)(struct charset_info_st *, const char *s, uint l, char **e, int base);
longlong (*strntoll)(struct charset_info_st *, const char *s, uint l, char **e, int base);
ulonglong (*strntoull)(struct charset_info_st *, const char *s, uint l, char **e, int base);
double (*strntod)(struct charset_info_st *, char *s, uint l, char **e);
long (*strntol)(struct charset_info_st *, const char *s, uint l, int base, char **e, int *err);
ulong (*strntoul)(struct charset_info_st *, const char *s, uint l, int base, char **e, int *err);
longlong (*strntoll)(struct charset_info_st *, const char *s, uint l, int base, char **e, int *err);
ulonglong (*strntoull)(struct charset_info_st *, const char *s, uint l, int base, char **e, int *err);
double (*strntod)(struct charset_info_st *, char *s, uint l, char **e, int *err);
} CHARSET_INFO;
......@@ -183,11 +183,11 @@ int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
int my_snprintf_8bit(struct charset_info_st *, char *to, uint n, const char *fmt, ...);
long my_strntol_8bit(CHARSET_INFO *, const char *s, uint l,char **e, int base);
ulong my_strntoul_8bit(CHARSET_INFO *, const char *s, uint l,char **e, int base);
longlong my_strntoll_8bit(CHARSET_INFO *, const char *s, uint l,char **e, int base);
ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, uint l,char **e, int base);
double my_strntod_8bit(CHARSET_INFO *, char *s, uint l,char **e);
long my_strntol_8bit(CHARSET_INFO *, const char *s, uint l, int base, char **e, int *err);
ulong my_strntoul_8bit(CHARSET_INFO *, const char *s, uint l, int base, char **e, int *err);
longlong my_strntoll_8bit(CHARSET_INFO *, const char *s, uint l, int base, char **e, int *err);
ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, uint l, int base, char **e, int *err);
double my_strntod_8bit(CHARSET_INFO *, char *s, uint l,char **e, int *err);
int my_long10_to_str_8bit(CHARSET_INFO *, char *to, uint l, int radix, long int val);
int my_longlong10_to_str_8bit(CHARSET_INFO *, char *to, uint l, int radix, longlong val);
......@@ -274,11 +274,11 @@ int my_wildcmp_mb(CHARSET_INFO *,
#define my_strcasecmp(s, a, b) ((s)->strcasecmp((s), (a), (b)))
#define my_strncasecmp(s, a, b, l) ((s)->strncasecmp((s), (a), (b), (l)))
#define my_strntol(s, a, b, c, d) ((s)->strntol((s),(a),(b),(c),(d)))
#define my_strntoul(s, a, b, c, d) ((s)->strntoul((s),(a),(b),(c),(d)))
#define my_strntoll(s, a, b, c, d) ((s)->strntoll((s),(a),(b),(c),(d)))
#define my_strntoull(s, a, b, c,d) ((s)->strntoull((s),(a),(b),(c),(d)))
#define my_strntod(s, a, b, c ) ((s)->strntod((s),(a),(b),(c)))
#define my_strntol(s, a, b, c, d, e) ((s)->strntol((s),(a),(b),(c),(d),(e)))
#define my_strntoul(s, a, b, c, d, e) ((s)->strntoul((s),(a),(b),(c),(d),(e)))
#define my_strntoll(s, a, b, c, d, e) ((s)->strntoll((s),(a),(b),(c),(d),(e)))
#define my_strntoull(s, a, b, c,d, e) ((s)->strntoull((s),(a),(b),(c),(d),(e)))
#define my_strntod(s, a, b, c, d) ((s)->strntod((s),(a),(b),(c),(d)))
/* XXX: still need to take care of this one */
......
......@@ -4522,41 +4522,42 @@ static void send_data_double(MYSQL_BIND *param, double value)
static void send_data_str(MYSQL_BIND *param, char *value, uint length)
{
char *buffer= param->buffer;
int err=0;
switch(param->buffer_type) {
case MYSQL_TYPE_TINY:
{
uchar data= (uchar)my_strntol(system_charset_info,value,length,NULL,10);
uchar data= (uchar)my_strntol(system_charset_info,value,length,10,NULL,&err);
*buffer= data;
break;
}
case MYSQL_TYPE_SHORT:
{
short data= (short)my_strntol(system_charset_info,value,length,NULL,10);
short data= (short)my_strntol(system_charset_info,value,length,10,NULL,&err);
int2store(buffer, data);
break;
}
case MYSQL_TYPE_LONG:
{
int32 data= (int32)my_strntol(system_charset_info,value,length,NULL,10);
int32 data= (int32)my_strntol(system_charset_info,value,length,10,NULL,&err);
int4store(buffer, data);
break;
}
case MYSQL_TYPE_LONGLONG:
{
longlong data= my_strntoll(system_charset_info,value,length,NULL,10);
longlong data= my_strntoll(system_charset_info,value,length,10,NULL,&err);
int8store(buffer, data);
break;
}
case MYSQL_TYPE_FLOAT:
{
float data = (float)my_strntod(system_charset_info,value,length,NULL);
float data = (float)my_strntod(system_charset_info,value,length,NULL,&err);
float4store(buffer, data);
break;
}
case MYSQL_TYPE_DOUBLE:
{
double data= my_strntod(system_charset_info,value,length,NULL);
double data= my_strntod(system_charset_info,value,length,NULL,&err);
float8store(buffer, data);
break;
}
......
......@@ -840,15 +840,17 @@ int Field_decimal::store(longlong nr)
double Field_decimal::val_real(void)
{
return my_strntod(my_charset_bin, ptr, field_length, NULL);
int err;
return my_strntod(my_charset_bin, ptr, field_length, NULL, &err);
}
longlong Field_decimal::val_int(void)
{
int err;
if (unsigned_flag)
return my_strntoull(my_charset_bin, ptr, field_length, NULL, 10);
return my_strntoull(my_charset_bin, ptr, field_length, 10, NULL, &err);
else
return my_strntoll( my_charset_bin, ptr, field_length, NULL, 10);
return my_strntoll( my_charset_bin, ptr, field_length, 10, NULL, &err);
}
......@@ -950,8 +952,9 @@ void Field_decimal::sql_type(String &res) const
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
{
int err;
char *end;
long tmp= my_strntol(cs, from, len, &end,10);
long tmp= my_strntol(cs, from, len, 10, &end, &err);
int error= 0;
if (unsigned_flag)
......@@ -1151,8 +1154,9 @@ void Field_tiny::sql_type(String &res) const
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
{
int err;
char *end;
long tmp= my_strntol(cs, from, len, &end, 10);
long tmp= my_strntol(cs, from, len, 10, &end, &err);
int error= 0;
if (unsigned_flag)
{
......@@ -1423,8 +1427,9 @@ void Field_short::sql_type(String &res) const
int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
{
int err;
char *end;
long tmp= my_strntol(cs, from, len, &end, 10);
long tmp= my_strntol(cs, from, len, 10, &end, &err);
int error= 0;
if (unsigned_flag)
......@@ -1659,16 +1664,15 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
error= 1;
}
else
tmp=(long) my_strntoul(cs,from,len,&end,10);
tmp=(long) my_strntoul(cs,from,len,10,&end,&error);
}
else
tmp=my_strntol(cs,from,len,&end,10);
if (my_errno ||
tmp=my_strntol(cs,from,len,10,&end,&error);
if (error ||
(from+len != end && current_thd->count_cuted_fields &&
!test_if_int(from,len,end,cs)))
{
current_thd->cuted_fields++;
error= 1;
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
......@@ -1918,11 +1922,11 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
error= 1;
}
else
tmp=(longlong) my_strntoull(cs,from,len,&end,10);
tmp=(longlong) my_strntoull(cs,from,len,10,&end,&error);
}
else
tmp=my_strntoll(cs,from,len,&end,10);
if (my_errno ||
tmp=my_strntoll(cs,from,len,10,&end,&error);
if (error ||
(from+len != end && current_thd->count_cuted_fields &&
!test_if_int(from,len,end,cs)))
current_thd->cuted_fields++;
......@@ -2130,14 +2134,14 @@ void Field_longlong::sql_type(String &res) const
int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
{
errno=0; // my_strntod() changes errno
Field_float::store(my_strntod(cs,(char*) from,len,(char**)NULL));
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
int err=0;
Field_float::store(my_strntod(cs,(char*) from,len,(char**)NULL,&err));
if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
{
current_thd->cuted_fields++;
return 1;
}
return (errno) ? 1 : 0;
return (err) ? 1 : 0;
}
......@@ -2403,19 +2407,17 @@ void Field_float::sql_type(String &res) const
int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
{
errno=0; // my_strntod() changes errno
int error= 0;
double j= my_strntod(cs,(char*) from,len,(char**)0);
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
int err= 0;
double j= my_strntod(cs,(char*) from,len,(char**)0,&err);
if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
{
current_thd->cuted_fields++;
error= 1;
}
if (unsigned_flag && j < 0)
{
current_thd->cuted_fields++;
j=0;
error= 1;
err= 1;
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
......@@ -2425,7 +2427,7 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
else
#endif
doublestore(ptr,j);
return error;
return err;
}
......@@ -3191,8 +3193,9 @@ void Field_time::sql_type(String &res) const
int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
{
int err;
char *end;
long nr= my_strntol(cs, from, len, &end, 10);
long nr= my_strntol(cs, from, len, 10, &end, &err);
if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155)
{
......@@ -3929,15 +3932,17 @@ int Field_string::store(longlong nr)
double Field_string::val_real(void)
{
int err;
CHARSET_INFO *cs=charset();
return my_strntod(cs,ptr,field_length,(char**)0);
return my_strntod(cs,ptr,field_length,(char**)0,&err);
}
longlong Field_string::val_int(void)
{
int err;
CHARSET_INFO *cs=charset();
return my_strntoll(cs,ptr,field_length,NULL,10);
return my_strntoll(cs,ptr,field_length,10,NULL,&err);
}
......@@ -4096,17 +4101,19 @@ int Field_varstring::store(longlong nr)
double Field_varstring::val_real(void)
{
int err;
uint length=uint2korr(ptr)+2;
CHARSET_INFO *cs=charset();
return my_strntod(cs,ptr+2,length,(char**)0);
return my_strntod(cs,ptr+2,length,(char**)0,&err);
}
longlong Field_varstring::val_int(void)
{
int err;
uint length=uint2korr(ptr)+2;
CHARSET_INFO *cs=charset();
return my_strntoll(cs,ptr+2,length,NULL,10);
return my_strntoll(cs,ptr+2,length,10,NULL,&err);
}
......@@ -4414,24 +4421,26 @@ int Field_blob::store(longlong nr)
double Field_blob::val_real(void)
{
int err;
char *blob;
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
if (!blob)
return 0.0;
uint32 length=get_length(ptr);
CHARSET_INFO *cs=charset();
return my_strntod(cs,blob,length,(char**)0);
return my_strntod(cs,blob,length,(char**)0,&err);
}
longlong Field_blob::val_int(void)
{
int err;
char *blob;
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
if (!blob)
return 0;
uint32 length=get_length(ptr);
return my_strntoll(charset(),blob,length,NULL,10);
return my_strntoll(charset(),blob,length,10,NULL,&err);
}
......@@ -4846,7 +4855,7 @@ uint find_enum(TYPELIB *lib,const char *x, uint length)
int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
{
int error= 0;
int err= 0;
uint tmp=find_enum(typelib,from,length);
if (!tmp)
{
......@@ -4854,20 +4863,18 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
{
/* This is for reading numbers with LOAD DATA INFILE */
char *end;
my_errno=0;
tmp=(uint) my_strntoul(cs,from,length,&end,10);
if (my_errno || end != from+length || tmp > typelib->count)
tmp=(uint) my_strntoul(cs,from,length,10,&end,&err);
if (err || end != from+length || tmp > typelib->count)
{
tmp=0;
current_thd->cuted_fields++;
error=1;
}
}
else
current_thd->cuted_fields++;
}
store_type((ulonglong) tmp);
return error;
return err;
}
......@@ -5052,7 +5059,7 @@ ulonglong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos,
int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
{
int error= 0;
int err= 0;
char *not_used;
uint not_used2;
......@@ -5061,19 +5068,17 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
{
/* This is for reading numbers with LOAD DATA INFILE */
char *end;
my_errno=0;
tmp=my_strntoull(cs,from,length,&end,10);
if (my_errno || end != from+length ||
tmp=my_strntoull(cs,from,length,10,&end,&err);
if (err || end != from+length ||
tmp > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1))
{
tmp=0;
error=1;
}
else
current_thd->cuted_fields--; // Remove warning from find_set
}
store_type(tmp);
return error;
return err;
}
......
......@@ -378,10 +378,11 @@ int Item_param::save_in_field(Field *field, bool no_conversions)
double Item_param::val()
{
int err;
switch (item_result_type) {
case STRING_RESULT:
return (double) my_strntod(str_value.charset(), (char*) str_value.ptr(),
str_value.length(), (char**) 0);
str_value.length(), (char**) 0, &err);
case INT_RESULT:
return (double)int_value;
default:
......@@ -392,9 +393,12 @@ double Item_param::val()
longlong Item_param::val_int()
{
int err;
switch (item_result_type) {
case STRING_RESULT:
return my_strntoll(str_value.charset(),str_value.ptr(),str_value.length(),(char**) 0,10);
return my_strntoll(str_value.charset(),
str_value.ptr(),str_value.length(),10,
(char**) 0,&err);
case REAL_RESULT:
return (longlong) (real_value+(real_value > 0 ? 0.5 : -0.5));
default:
......@@ -1263,17 +1267,19 @@ void Item_cache_str::store(Item *item)
}
double Item_cache_str::val()
{
int err;
if (value)
return my_strntod(value->charset(), (char*) value->ptr(),
value->length(), (char**) 0);
value->length(), (char**) 0, &err);
else
return (double)0;
}
longlong Item_cache_str::val_int()
{
int err;
if (value)
return my_strntoll(value->charset(), value->ptr(),
value->length(), (char**) 0, 10);
value->length(), 10, (char**) 0, &err);
else
return (longlong)0;
}
......
......@@ -344,13 +344,15 @@ public:
enum Type type() const { return STRING_ITEM; }
double val()
{
int err;
return my_strntod(str_value.charset(), (char*) str_value.ptr(),
str_value.length(), (char**) 0);
str_value.length(), (char**) 0, &err);
}
longlong val_int()
{
int err;
return my_strntoll(str_value.charset(), str_value.ptr(),
str_value.length(), (char**) 0, 10);
str_value.length(), 10, (char**) 0, &err);
}
String *val_str(String*) { return (String*) &str_value; }
int save_in_field(Field *field, bool no_conversions);
......@@ -599,12 +601,16 @@ public:
enum_field_types field_type() const { return cached_field_type; }
double val()
{
int err;
return (null_value ? 0.0 :
my_strntod(str_value.charset(), (char*) str_value.ptr(),
str_value.length(),NULL));
str_value.length(),NULL,&err));
}
longlong val_int()
{ return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),str_value.length(),(char**) 0,10); }
{
int err;
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),str_value.length(),10, (char**) 0,&err);
}
String *val_str(String*);
void make_field(Send_field *field) { item->make_field(field); }
void copy();
......
......@@ -812,13 +812,15 @@ public:
String *val_str(String *);
double val()
{
int err;
String *res; res=val_str(&str_value);
return res ? my_strntod(res->charset(),(char*) res->ptr(),res->length(),0) : 0.0;
return res ? my_strntod(res->charset(),(char*) res->ptr(),res->length(),0,&err) : 0.0;
}
longlong val_int()
{
int err;
String *res; res=val_str(&str_value);
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),(char**) 0,10) : (longlong) 0;
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,(char**) 0,&err) : (longlong) 0;
}
enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec();
......
......@@ -52,17 +52,19 @@ uint nr_of_decimals(const char *str)
double Item_str_func::val()
{
int err;
String *res;
res=val_str(&str_value);
return res ? my_strntod(res->charset(), (char*) res->ptr(),res->length(),
NULL) : 0.0;
NULL, &err) : 0.0;
}
longlong Item_str_func::val_int()
{
int err;
String *res;
res=val_str(&str_value);
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),NULL,10) : (longlong) 0;
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,NULL,&err) : (longlong) 0;
}
......@@ -1956,6 +1958,7 @@ String *Item_func_conv::val_str(String *str)
longlong dec;
int from_base= (int) args[1]->val_int();
int to_base= (int) args[2]->val_int();
int err;
if (args[0]->null_value || args[1]->null_value || args[2]->null_value ||
abs(to_base) > 36 || abs(to_base) < 2 ||
......@@ -1966,9 +1969,9 @@ String *Item_func_conv::val_str(String *str)
}
null_value=0;
if (from_base < 0)
dec= my_strntoll(res->charset(),res->ptr(),res->length(),&endptr,-from_base);
dec= my_strntoll(res->charset(),res->ptr(),res->length(),-from_base,&endptr,&err);
else
dec= (longlong) my_strntoull(res->charset(),res->ptr(),res->length(),&endptr,from_base);
dec= (longlong) my_strntoull(res->charset(),res->ptr(),res->length(),from_base,&endptr,&err);
ptr= longlong2str(dec,ans,to_base);
if (str->copy(ans,(uint32) (ptr-ans), thd_charset()))
return &empty_string;
......
......@@ -336,13 +336,14 @@ void Item_sum_variance::update_field(int offset)
double Item_sum_hybrid::val()
{
int err;
if (null_value)
return 0.0;
switch (hybrid_type) {
case STRING_RESULT:
String *res; res=val_str(&str_value);
return (res ? my_strntod(res->charset(), (char*) res->ptr(),res->length(),
(char**) 0) : 0.0);
(char**) 0, &err) : 0.0);
case INT_RESULT:
if (unsigned_flag)
return ulonglong2double(sum_int);
......
......@@ -483,14 +483,16 @@ public:
String *val_str(String *);
double val()
{
int err;
String *res; res=val_str(&str_value);
return res ? my_strntod(res->charset(),(char*) res->ptr(),res->length(),
(char**) 0) : 0.0;
(char**) 0, &err) : 0.0;
}
longlong val_int()
{
int err;
String *res; res=val_str(&str_value);
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),(char**) 0,10) : (longlong) 0;
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10, (char**) 0, &err) : (longlong) 0;
}
enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec();
......
......@@ -4666,9 +4666,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
berkeley_lock_type=berkeley_lock_types[type-1];
else
{
int err;
char *end;
uint length= strlen(argument);
long value= my_strntol(my_charset_latin1, argument, length, &end, 10);
long value= my_strntol(my_charset_latin1, argument, length, 10, &end, &err);
if (test_if_int(argument,(uint) length, end, my_charset_latin1))
berkeley_lock_scan_time= value;
else
......
......@@ -59,7 +59,7 @@ public:
void set(double nr) { value=nr; }
void set(longlong nr) { value=(double) nr; }
void set(const char *str,uint length,CHARSET_INFO *cs)
{ value=my_strntod(cs,(char*) str,length,(char**)0); }
{ int err; value=my_strntod(cs,(char*) str,length,(char**)0,&err); }
double val() { return value; }
longlong val_int() { return (longlong) value; }
String *val_str(String *s) { s->set(value,decimals,thd_charset()); return s; }
......@@ -77,7 +77,7 @@ public:
void set(double nr) { value=(longlong) nr; }
void set(longlong nr) { value=nr; }
void set(const char *str,uint length, CHARSET_INFO *cs)
{ value=my_strntoll(cs,str,length,NULL,10); }
{ int err; value=my_strntoll(cs,str,length,10,NULL,&err); }
double val() { return (double) value; }
longlong val_int() { return value; }
String *val_str(String *s) { s->set(value, thd_charset()); return s; }
......@@ -98,14 +98,16 @@ public:
{ str_value.copy(str,length,cs); }
double val()
{
int err;
CHARSET_INFO *cs=str_value.charset();
return my_strntod(cs, (char*) str_value.ptr(), str_value.length(),
(char**) 0);
(char**) 0, &err);
}
longlong val_int()
{
int err;
CHARSET_INFO *cs=str_value.charset();
return my_strntoll(cs,str_value.ptr(),str_value.length(),NULL,10);
return my_strntoll(cs,str_value.ptr(),str_value.length(),10,NULL,&err);
}
String *val_str(String*)
{
......
......@@ -17,7 +17,6 @@
#include <my_global.h>
#include "m_string.h"
#include "m_ctype.h"
#include "my_sys.h" /* defines errno */
#include <errno.h>
#include "stdarg.h"
......@@ -203,7 +202,8 @@ void my_hash_sort_simple(CHARSET_INFO *cs,
long my_strntol_8bit(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative;
register ulong cutoff;
......@@ -303,14 +303,14 @@ long my_strntol_8bit(CHARSET_INFO *cs,
if (overflow)
{
my_errno=(ERANGE);
err[0]= ERANGE;
return negative ? LONG_MIN : LONG_MAX;
}
return (negative ? -((long) i) : (long) i);
noconv:
my_errno=(EDOM);
err[0]= EDOM;
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
......@@ -318,7 +318,8 @@ noconv:
ulong my_strntoul_8bit(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative;
register ulong cutoff;
......@@ -409,14 +410,14 @@ ulong my_strntoul_8bit(CHARSET_INFO *cs,
if (overflow)
{
my_errno=(ERANGE);
err[0]= ERANGE;
return ((ulong)~0L);
}
return (negative ? -((long) i) : (long) i);
noconv:
my_errno=(EDOM);
err[0]= EDOM;
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
......@@ -424,7 +425,8 @@ noconv:
longlong my_strntoll_8bit(CHARSET_INFO *cs __attribute__((unused)),
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr,int *err)
{
int negative;
register ulonglong cutoff;
......@@ -524,14 +526,14 @@ longlong my_strntoll_8bit(CHARSET_INFO *cs __attribute__((unused)),
if (overflow)
{
my_errno=(ERANGE);
err[0]= ERANGE;
return negative ? LONGLONG_MIN : LONGLONG_MAX;
}
return (negative ? -((longlong) i) : (longlong) i);
noconv:
my_errno=(EDOM);
err[0]= EDOM;
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
......@@ -539,7 +541,8 @@ noconv:
ulonglong my_strntoull_8bit(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative;
register ulonglong cutoff;
......@@ -631,14 +634,14 @@ ulonglong my_strntoull_8bit(CHARSET_INFO *cs,
if (overflow)
{
my_errno=(ERANGE);
err[0]= ERANGE;
return (~(ulonglong) 0);
}
return (negative ? -((longlong) i) : (longlong) i);
noconv:
my_errno=(EDOM);
err[0]= EDOM;
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
......@@ -667,7 +670,8 @@ noconv:
double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)),
char *str, uint length, char **end)
char *str, uint length,
char **end, int *err __attribute__ ((unused)))
{
char end_char;
double result;
......
......@@ -21,7 +21,6 @@
#include <my_global.h>
#include "m_string.h"
#include "m_ctype.h"
#include "my_sys.h" /* defines errno */
#include <errno.h>
#ifdef HAVE_CHARSET_utf8
......@@ -2446,7 +2445,8 @@ static int my_snprintf_ucs2(CHARSET_INFO *cs __attribute__((unused))
long my_strntol_ucs2(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative=0;
int overflow;
......@@ -2475,7 +2475,7 @@ long my_strntol_ucs2(CHARSET_INFO *cs,
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
return 0;
}
s+=cnv;
......@@ -2518,7 +2518,7 @@ bs:
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno=EILSEQ;
err[0]=EILSEQ;
return 0;
}
else
......@@ -2533,7 +2533,7 @@ bs:
if (s == save)
{
my_errno=EDOM;
err[0]=EDOM;
return 0L;
}
......@@ -2547,7 +2547,7 @@ bs:
if (overflow)
{
my_errno=(ERANGE);
err[0]=ERANGE;
return negative ? LONG_MIN : LONG_MAX;
}
......@@ -2556,7 +2556,8 @@ bs:
ulong my_strntoul_ucs2(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative=0;
int overflow;
......@@ -2585,7 +2586,7 @@ ulong my_strntoul_ucs2(CHARSET_INFO *cs,
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
return 0;
}
s+=cnv;
......@@ -2628,7 +2629,7 @@ bs:
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno=EILSEQ;
err[0]=EILSEQ;
return 0;
}
else
......@@ -2643,13 +2644,13 @@ bs:
if (s == save)
{
my_errno=EDOM;
err[0]=EDOM;
return 0L;
}
if (overflow)
{
my_errno=(ERANGE);
err[0]=(ERANGE);
return ((ulong)~0L);
}
......@@ -2660,7 +2661,8 @@ bs:
longlong my_strntoll_ucs2(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative=0;
int overflow;
......@@ -2689,7 +2691,7 @@ longlong my_strntoll_ucs2(CHARSET_INFO *cs,
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
err[0] = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
return 0;
}
s+=cnv;
......@@ -2732,7 +2734,7 @@ bs:
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno=EILSEQ;
err[0]=EILSEQ;
return 0;
}
else
......@@ -2747,7 +2749,7 @@ bs:
if (s == save)
{
my_errno=EDOM;
err[0]=EDOM;
return 0L;
}
......@@ -2761,7 +2763,7 @@ bs:
if (overflow)
{
my_errno=(ERANGE);
err[0]=ERANGE;
return negative ? LONGLONG_MIN : LONGLONG_MAX;
}
......@@ -2772,7 +2774,8 @@ bs:
ulonglong my_strntoull_ucs2(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
const char *nptr, uint l, int base,
char **endptr, int *err)
{
int negative=0;
int overflow;
......@@ -2801,7 +2804,7 @@ ulonglong my_strntoull_ucs2(CHARSET_INFO *cs,
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno = (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
err[0]= (cnv==MY_CS_ILSEQ) ? EILSEQ : EDOM;
return 0;
}
s+=cnv;
......@@ -2844,7 +2847,7 @@ bs:
{
if (endptr !=NULL )
*endptr = (char*)s;
my_errno=EILSEQ;
err[0]= EILSEQ;
return 0;
}
else
......@@ -2859,13 +2862,13 @@ bs:
if (s == save)
{
my_errno=EDOM;
err[0]= EDOM;
return 0L;
}
if (overflow)
{
my_errno=(ERANGE);
err[0]= ERANGE;
return (~(ulonglong) 0);
}
......@@ -2874,7 +2877,8 @@ bs:
double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)),
char *nptr, uint length, char **endptr)
char *nptr, uint length,
char **endptr, int *err __attribute__ ((unused)))
{
char buf[256];
double res;
......
......@@ -3983,6 +3983,7 @@ typedef struct my_cs_file_info
static int fill_uchar(uchar *a,uint size,const char *str, uint len)
{
int err=0;
uint i= 0;
const char *s, *b, *e=str+len;
......@@ -3993,7 +3994,7 @@ static int fill_uchar(uchar *a,uint size,const char *str, uint len)
for ( ; (s < e) && !strchr(" \t\r\n",s[0]); s++) ;
if (s == b || i > size)
break;
a[i]= my_strntoul(my_charset_latin1,b,s-b,NULL,16);
a[i]= my_strntoul(my_charset_latin1,b,s-b,16,NULL,&err);
}
return 0;
}
......@@ -4001,6 +4002,8 @@ static int fill_uchar(uchar *a,uint size,const char *str, uint len)
static int fill_uint16(uint16 *a,uint size,const char *str, uint len)
{
uint i= 0;
int err;
const char *s, *b, *e=str+len;
for (s=str ; s < e ; i++)
{
......@@ -4009,7 +4012,7 @@ static int fill_uint16(uint16 *a,uint size,const char *str, uint len)
for ( ; (s < e) && !strchr(" \t\r\n",s[0]); s++) ;
if (s == b || i > size)
break;
a[i]= my_strntol(my_charset_latin1,b,s-b,NULL,16);
a[i]= my_strntol(my_charset_latin1,b,s-b,16,NULL,&err);
}
return 0;
}
......@@ -4051,6 +4054,7 @@ static int cs_value(MY_XML_PARSER *st,const char *attr, uint len)
struct my_cs_file_info *i= (struct my_cs_file_info *)st->user_data;
struct my_cs_file_section_st *s;
int state= (s=cs_file_sec(st->attr,strlen(st->attr))) ? s->state : 0;
int err;
#ifndef DBUG_OFF
if(0){
......@@ -4062,7 +4066,7 @@ static int cs_value(MY_XML_PARSER *st,const char *attr, uint len)
switch (state) {
case _CS_ID:
i->cs.number= my_strntoul(my_charset_latin1,attr,len,(char**)NULL,0);
i->cs.number= my_strntoul(my_charset_latin1,attr,len,0,(char**)NULL,&err);
break;
case _CS_COLNAME:
i->cs.name=mstr(i->name,attr,len,MY_CS_NAME_SIZE-1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment