mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from 'size_t' to 'type', possible loss of data)
Handle string length as size_t, consistently (almost always:)) Change function prototypes to accept size_t, where in the past ulong or uint were used. change local/member variables to size_t when appropriate. This fix excludes rocksdb, spider,spider, sphinx and connect for now.
This commit is contained in:
@ -240,8 +240,8 @@ bool String::copy(const char *str,size_t arg_length, CHARSET_INFO *cs)
|
||||
{
|
||||
if (alloc(arg_length))
|
||||
return TRUE;
|
||||
DBUG_ASSERT(arg_length < UINT_MAX32);
|
||||
if ((str_length=arg_length))
|
||||
DBUG_ASSERT(arg_length <= UINT_MAX32);
|
||||
if ((str_length=(uint32)arg_length))
|
||||
memcpy(Ptr,str,arg_length);
|
||||
Ptr[arg_length]=0;
|
||||
str_charset=cs;
|
||||
@ -271,7 +271,7 @@ bool String::copy(const char *str,size_t arg_length, CHARSET_INFO *cs)
|
||||
character_set_results is NULL.
|
||||
*/
|
||||
|
||||
bool String::needs_conversion(uint32 arg_length,
|
||||
bool String::needs_conversion(size_t arg_length,
|
||||
CHARSET_INFO *from_cs,
|
||||
CHARSET_INFO *to_cs,
|
||||
uint32 *offset)
|
||||
@ -282,7 +282,7 @@ bool String::needs_conversion(uint32 arg_length,
|
||||
(to_cs == from_cs) ||
|
||||
my_charset_same(from_cs, to_cs) ||
|
||||
((from_cs == &my_charset_bin) &&
|
||||
(!(*offset=(arg_length % to_cs->mbminlen)))))
|
||||
(!(*offset=(uint32)(arg_length % to_cs->mbminlen)))))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
@ -300,7 +300,7 @@ bool String::needs_conversion(uint32 arg_length,
|
||||
|
||||
@return conversion needed
|
||||
*/
|
||||
bool String::needs_conversion_on_storage(uint32 arg_length,
|
||||
bool String::needs_conversion_on_storage(size_t arg_length,
|
||||
CHARSET_INFO *cs_from,
|
||||
CHARSET_INFO *cs_to)
|
||||
{
|
||||
@ -349,14 +349,14 @@ bool String::needs_conversion_on_storage(uint32 arg_length,
|
||||
1 error
|
||||
*/
|
||||
|
||||
bool String::copy_aligned(const char *str,uint32 arg_length, uint32 offset,
|
||||
bool String::copy_aligned(const char *str, size_t arg_length, size_t offset,
|
||||
CHARSET_INFO *cs)
|
||||
{
|
||||
/* How many bytes are in incomplete character */
|
||||
offset= cs->mbminlen - offset; /* How many zeros we should prepend */
|
||||
DBUG_ASSERT(offset && offset != cs->mbminlen);
|
||||
|
||||
uint32 aligned_length= arg_length + offset;
|
||||
size_t aligned_length= arg_length + offset;
|
||||
if (alloc(aligned_length))
|
||||
return TRUE;
|
||||
|
||||
@ -369,17 +369,17 @@ bool String::copy_aligned(const char *str,uint32 arg_length, uint32 offset,
|
||||
memcpy(Ptr + offset, str, arg_length);
|
||||
Ptr[aligned_length]=0;
|
||||
/* str_length is always >= 0 as arg_length is != 0 */
|
||||
str_length= aligned_length;
|
||||
str_length= (uint32)aligned_length;
|
||||
str_charset= cs;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
|
||||
bool String::set_or_copy_aligned(const char *str, size_t arg_length,
|
||||
CHARSET_INFO *cs)
|
||||
{
|
||||
/* How many bytes are in incomplete character */
|
||||
uint32 offset= (arg_length % cs->mbminlen);
|
||||
size_t offset= (arg_length % cs->mbminlen);
|
||||
|
||||
if (!offset) /* All characters are complete, just copy */
|
||||
{
|
||||
@ -400,7 +400,7 @@ bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
|
||||
|
||||
*/
|
||||
|
||||
bool String::copy(const char *str, uint32 arg_length,
|
||||
bool String::copy(const char *str, size_t arg_length,
|
||||
CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
|
||||
{
|
||||
uint32 offset;
|
||||
@ -417,7 +417,7 @@ bool String::copy(const char *str, uint32 arg_length,
|
||||
*errors= 0;
|
||||
return copy_aligned(str, arg_length, offset, to_cs);
|
||||
}
|
||||
uint32 new_length= to_cs->mbmaxlen*arg_length;
|
||||
size_t new_length= to_cs->mbmaxlen*arg_length;
|
||||
if (alloc(new_length))
|
||||
return TRUE;
|
||||
str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
|
||||
@ -446,7 +446,7 @@ bool String::copy(const char *str, uint32 arg_length,
|
||||
|
||||
*/
|
||||
|
||||
bool String::set_ascii(const char *str, uint32 arg_length)
|
||||
bool String::set_ascii(const char *str, size_t arg_length)
|
||||
{
|
||||
if (str_charset->mbminlen == 1)
|
||||
{
|
||||
@ -454,7 +454,7 @@ bool String::set_ascii(const char *str, uint32 arg_length)
|
||||
return 0;
|
||||
}
|
||||
uint dummy_errors;
|
||||
return copy(str, arg_length, &my_charset_latin1, str_charset, &dummy_errors);
|
||||
return copy(str, (uint32)arg_length, &my_charset_latin1, str_charset, &dummy_errors);
|
||||
}
|
||||
|
||||
|
||||
@ -563,13 +563,13 @@ bool String::append_ulonglong(ulonglong val)
|
||||
with character set recoding
|
||||
*/
|
||||
|
||||
bool String::append(const char *s, uint arg_length, CHARSET_INFO *cs)
|
||||
bool String::append(const char *s, size_t arg_length, CHARSET_INFO *cs)
|
||||
{
|
||||
uint32 offset;
|
||||
|
||||
if (needs_conversion(arg_length, cs, str_charset, &offset))
|
||||
if (needs_conversion((uint32)arg_length, cs, str_charset, &offset))
|
||||
{
|
||||
uint32 add_length;
|
||||
size_t add_length;
|
||||
if ((cs == &my_charset_bin) && offset)
|
||||
{
|
||||
DBUG_ASSERT(str_charset->mbminlen > offset);
|
||||
@ -579,7 +579,7 @@ bool String::append(const char *s, uint arg_length, CHARSET_INFO *cs)
|
||||
return TRUE;
|
||||
bzero((char*) Ptr + str_length, offset);
|
||||
memcpy(Ptr + str_length + offset, s, arg_length);
|
||||
str_length+= add_length;
|
||||
str_length+= (uint32)add_length;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -587,15 +587,15 @@ bool String::append(const char *s, uint arg_length, CHARSET_INFO *cs)
|
||||
uint dummy_errors;
|
||||
if (realloc_with_extra_if_needed(str_length + add_length))
|
||||
return TRUE;
|
||||
str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
|
||||
s, arg_length, cs, &dummy_errors);
|
||||
str_length+= copy_and_convert(Ptr+str_length, (uint32)add_length, str_charset,
|
||||
s, (uint32)arg_length, cs, &dummy_errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (realloc_with_extra_if_needed(str_length + arg_length))
|
||||
return TRUE;
|
||||
memcpy(Ptr + str_length, s, arg_length);
|
||||
str_length+= arg_length;
|
||||
str_length+= (uint32)arg_length;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@ -760,7 +760,7 @@ bool String::replace(uint32 offset,uint32 arg_length,
|
||||
|
||||
|
||||
// added by Holyfoot for "geometry" needs
|
||||
int String::reserve(uint32 space_needed, uint32 grow_by)
|
||||
int String::reserve(size_t space_needed, size_t grow_by)
|
||||
{
|
||||
if (Alloced_length < str_length + space_needed)
|
||||
{
|
||||
@ -770,10 +770,10 @@ int String::reserve(uint32 space_needed, uint32 grow_by)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void String::qs_append(const char *str, uint32 len)
|
||||
void String::qs_append(const char *str, size_t len)
|
||||
{
|
||||
memcpy(Ptr + str_length, str, len + 1);
|
||||
str_length += len;
|
||||
str_length += (uint32)len;
|
||||
}
|
||||
|
||||
void String::qs_append(double d)
|
||||
@ -1072,10 +1072,9 @@ my_copy_with_hex_escaping(CHARSET_INFO *cs,
|
||||
*/
|
||||
uint
|
||||
String_copier::well_formed_copy(CHARSET_INFO *to_cs,
|
||||
char *to, uint to_length,
|
||||
char *to, size_t to_length,
|
||||
CHARSET_INFO *from_cs,
|
||||
const char *from, uint from_length,
|
||||
uint nchars)
|
||||
const char *from, size_t from_length, size_t nchars)
|
||||
{
|
||||
if ((to_cs == &my_charset_bin) ||
|
||||
(from_cs == &my_charset_bin) ||
|
||||
@ -1098,7 +1097,7 @@ String_copier::well_formed_copy(CHARSET_INFO *to_cs,
|
||||
Does not add the enclosing quotes, this is left up to caller.
|
||||
*/
|
||||
#define APPEND(X) if (append(X)) return 1; else break
|
||||
bool String::append_for_single_quote(const char *st, uint len)
|
||||
bool String::append_for_single_quote(const char *st, size_t len)
|
||||
{
|
||||
const char *end= st+len;
|
||||
for (; st < end; st++)
|
||||
|
Reference in New Issue
Block a user