1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +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:
Vladislav Vaintroub
2018-02-06 12:55:58 +00:00
parent f271100836
commit 6c279ad6a7
257 changed files with 1514 additions and 1543 deletions

View File

@ -35,12 +35,12 @@ typedef struct st_mem_root MEM_ROOT;
#include "pack.h"
int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
inline uint32 copy_and_convert(char *to, uint32 to_length,
inline uint32 copy_and_convert(char *to, size_t to_length,
CHARSET_INFO *to_cs,
const char *from, uint32 from_length,
const char *from, size_t from_length,
CHARSET_INFO *from_cs, uint *errors)
{
return my_convert(to, to_length, to_cs, from, from_length, from_cs, errors);
return my_convert(to, (uint)to_length, to_cs, from, (uint)from_length, from_cs, errors);
}
@ -97,9 +97,8 @@ public:
Convert a string between character sets.
"dstcs" and "srccs" cannot be &my_charset_bin.
*/
size_t convert_fix(CHARSET_INFO *dstcs, char *dst, uint dst_length,
CHARSET_INFO *srccs, const char *src, uint src_length,
uint nchars)
size_t convert_fix(CHARSET_INFO *dstcs, char *dst, size_t dst_length,
CHARSET_INFO *srccs, const char *src, size_t src_length, size_t nchars)
{
return my_convert_fix(dstcs, dst, dst_length,
srccs, src, src_length, nchars, this, this);
@ -107,13 +106,11 @@ public:
/*
Copy a string. Fix bad bytes/characters to '?'.
*/
uint well_formed_copy(CHARSET_INFO *to_cs, char *to, uint to_length,
CHARSET_INFO *from_cs, const char *from,
uint from_length, uint nchars);
uint well_formed_copy(CHARSET_INFO *to_cs, char *to, size_t to_length,
CHARSET_INFO *from_cs, const char *from, size_t from_length, size_t nchars);
// Same as above, but without the "nchars" limit.
uint well_formed_copy(CHARSET_INFO *to_cs, char *to, uint to_length,
CHARSET_INFO *from_cs, const char *from,
uint from_length)
uint well_formed_copy(CHARSET_INFO *to_cs, char *to, size_t to_length,
CHARSET_INFO *from_cs, const char *from, size_t from_length)
{
return well_formed_copy(to_cs, to, to_length,
from_cs, from, from_length,
@ -142,7 +139,7 @@ public:
alloced= thread_specific= 0;
str_charset= &my_charset_bin;
}
String(uint32 length_arg)
String(size_t length_arg)
{
alloced= thread_specific= 0;
Alloced_length= extra_alloc= 0; (void) real_alloc(length_arg);
@ -160,15 +157,15 @@ public:
contructors need the size of memory for STR to be at least LEN+1 (to make
room for zero termination).
*/
String(const char *str,uint32 len, CHARSET_INFO *cs)
String(const char *str,size_t len, CHARSET_INFO *cs)
{
Ptr=(char*) str; str_length=len; Alloced_length= extra_alloc=0;
Ptr=(char*) str; str_length=(uint32)len; Alloced_length= extra_alloc=0;
alloced= thread_specific= 0;
str_charset=cs;
}
String(char *str,uint32 len, CHARSET_INFO *cs)
String(char *str,size_t len, CHARSET_INFO *cs)
{
Ptr=(char*) str; Alloced_length=str_length=len; extra_alloc= 0;
Ptr=(char*) str; Alloced_length=str_length=(uint32)len; extra_alloc= 0;
alloced= thread_specific= 0;
str_charset=cs;
}
@ -180,7 +177,7 @@ public:
str_charset=str.str_charset;
}
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return (void*) alloc_root(mem_root, (uint) size); }
{ return (void*) alloc_root(mem_root, size); }
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void operator delete(void *ptr_arg, size_t size)
@ -209,9 +206,9 @@ public:
inline uint32 length() const { return str_length;}
inline uint32 alloced_length() const { return Alloced_length;}
inline uint32 extra_allocation() const { return extra_alloc;}
inline char& operator [] (uint32 i) const { return Ptr[i]; }
inline void length(uint32 len) { str_length=len ; }
inline void extra_allocation(uint32 len) { extra_alloc= len; }
inline char& operator [] (size_t i) const { return Ptr[i]; }
inline void length(size_t len) { str_length=(uint32)len ; }
inline void extra_allocation(size_t len) { extra_alloc= (uint32)len; }
inline bool is_empty() const { return (str_length == 0); }
inline void mark_as_const() { Alloced_length= 0;}
inline const char *ptr() const { return Ptr; }
@ -250,13 +247,13 @@ public:
return skr;
}
void set(String &str,uint32 offset,uint32 arg_length)
void set(String &str,size_t offset,size_t arg_length)
{
DBUG_ASSERT(&str != this);
free();
Ptr=(char*) str.ptr()+offset; str_length=arg_length;
Ptr=(char*) str.ptr()+offset; str_length=(uint32)arg_length;
if (str.Alloced_length)
Alloced_length=str.Alloced_length-offset;
Alloced_length=(uint32)(str.Alloced_length-offset);
str_charset=str.str_charset;
}
@ -269,24 +266,24 @@ public:
@param cs Character set to use for interpreting string data.
@note The new buffer will not be null terminated.
*/
inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs)
inline void set(char *str,size_t arg_length, CHARSET_INFO *cs)
{
free();
Ptr=(char*) str; str_length=Alloced_length=arg_length;
Ptr=(char*) str; str_length=Alloced_length=(uint32)arg_length;
str_charset=cs;
}
inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs)
inline void set(const char *str,size_t arg_length, CHARSET_INFO *cs)
{
free();
Ptr=(char*) str; str_length=arg_length;
Ptr=(char*) str; str_length=(uint32)arg_length;
str_charset=cs;
}
bool set_ascii(const char *str, uint32 arg_length);
inline void set_quick(char *str,uint32 arg_length, CHARSET_INFO *cs)
bool set_ascii(const char *str, size_t arg_length);
inline void set_quick(char *str,size_t arg_length, CHARSET_INFO *cs)
{
if (!alloced)
{
Ptr=(char*) str; str_length=Alloced_length=arg_length;
Ptr=(char*) str; str_length=Alloced_length=(uint32)arg_length;
}
str_charset=cs;
}
@ -303,13 +300,13 @@ public:
bool set_hex(const char *str, uint32 len);
/* Take over handling of buffer from some other object */
void reset(char *ptr_arg, uint32 length_arg, uint32 alloced_length_arg,
void reset(char *ptr_arg, size_t length_arg, size_t alloced_length_arg,
CHARSET_INFO *cs)
{
free();
Ptr= ptr_arg;
str_length= length_arg;
Alloced_length= alloced_length_arg;
str_length= (uint32)length_arg;
Alloced_length= (uint32)alloced_length_arg;
str_charset= cs;
alloced= ptr_arg != 0;
}
@ -438,29 +435,29 @@ public:
bool copy(); // Alloc string if not alloced
bool copy(const String &s); // Allocate new string
bool copy(const char *s,size_t arg_length, CHARSET_INFO *cs); // Allocate new string
static bool needs_conversion(uint32 arg_length,
static bool needs_conversion(size_t arg_length,
CHARSET_INFO *cs_from, CHARSET_INFO *cs_to,
uint32 *offset);
static bool needs_conversion_on_storage(uint32 arg_length,
static bool needs_conversion_on_storage(size_t arg_length,
CHARSET_INFO *cs_from,
CHARSET_INFO *cs_to);
bool copy_aligned(const char *s, uint32 arg_length, uint32 offset,
bool copy_aligned(const char *s, size_t arg_length, size_t offset,
CHARSET_INFO *cs);
bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs);
bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom,
bool set_or_copy_aligned(const char *s, size_t arg_length, CHARSET_INFO *cs);
bool copy(const char*s, size_t arg_length, CHARSET_INFO *csfrom,
CHARSET_INFO *csto, uint *errors);
bool copy(const String *str, CHARSET_INFO *tocs, uint *errors)
{
return copy(str->ptr(), str->length(), str->charset(), tocs, errors);
}
bool copy(CHARSET_INFO *tocs,
CHARSET_INFO *fromcs, const char *src, uint32 src_length,
uint32 nchars, String_copier *copier)
CHARSET_INFO *fromcs, const char *src, size_t src_length,
size_t nchars, String_copier *copier)
{
if (alloc(tocs->mbmaxlen * src_length))
return true;
str_length= copier->well_formed_copy(tocs, Ptr, Alloced_length,
fromcs, src, src_length, nchars);
fromcs, src, (uint)src_length, (uint)nchars);
str_charset= tocs;
return false;
}
@ -490,7 +487,7 @@ public:
return append(ls->str, (uint32) ls->length);
}
bool append(const char *s, size_t size);
bool append(const char *s, uint arg_length, CHARSET_INFO *cs);
bool append(const char *s, size_t arg_length, CHARSET_INFO *cs);
bool append_ulonglong(ulonglong val);
bool append_longlong(longlong val);
bool append(IO_CACHE* file, uint32 arg_length);
@ -538,11 +535,11 @@ public:
uint32 numchars() const;
int charpos(longlong i,uint32 offset=0);
int reserve(uint32 space_needed)
int reserve(size_t space_needed)
{
return realloc(str_length + space_needed);
}
int reserve(uint32 space_needed, uint32 grow_by);
int reserve(size_t space_needed, size_t grow_by);
/*
The following append operations do NOT check alloced memory
@ -601,9 +598,9 @@ public:
DBUG_ASSERT(ls->length < UINT_MAX32 &&
((ls->length == 0 && !ls->str) ||
ls->length == strlen(ls->str)));
qs_append(ls->str, ls->length);
qs_append(ls->str, (uint32)ls->length);
}
void qs_append(const char *str, uint32 len);
void qs_append(const char *str, size_t len);
void qs_append_hex(const char *str, uint32 len);
void qs_append(double d);
void qs_append(double *d);
@ -664,7 +661,7 @@ public:
print_with_conversion(to, cs);
}
bool append_for_single_quote(const char *st, uint len);
bool append_for_single_quote(const char *st, size_t len);
bool append_for_single_quote(const String *s)
{
return append_for_single_quote(s->ptr(), s->length());