Skip to content

Commit

Permalink
fix 32bit redefine of char_to_byte_length_safe (#337)
Browse files Browse the repository at this point in the history
* fix 32bit redefine of char_to_byte_length_safe

Error can be seen here: https://hastebin.com/azomatocoq.scala

sql/item.h: defined uint32 char_to_byte_length_safe(size_t, uint32)
sql/sql_type.h: defined uint32 char_to_byte_length_safe(uint32, uint32)

As @knielsen observed, C++ overloading allows this on 64bit
 because size_t and uint32 differ.

Since item.h does a #include "sql_type.h", there is no point in
redifining this function in item.h

* avoid -Wconversion warnings, fix spacing; thanks @svoj

From IRC:
<svoj> EricHerman: nice, thanks! I believe we also should use function body as in item.h. It was fixed by dr-m recently.
<EricHerman> svoj, so you suggest the "return tmp > UINT_MAX32 ? UINT_MAX32 : static_cast<uint32>(tmp);"
<EricHerman> I can use that, sure.
<svoj> EricHerman: yes, please! And fix indentation on these lines (should be 2 spaces instead of 3).
<svoj> EricHerman: the patch where this hunk comes from: git show 89d80c1 sql/item.h
  • Loading branch information
ericherman authored and Sergey Vojtovich committed Mar 15, 2017
1 parent 7aa09a5 commit 6a9e2e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 0 additions & 7 deletions sql/item.h
Expand Up @@ -96,13 +96,6 @@ enum precedence {

typedef Bounds_checked_array<Item*> Ref_ptr_array;

static inline uint32
char_to_byte_length_safe(size_t char_length_arg, uint32 mbmaxlen_arg)
{
ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
return tmp > UINT_MAX32 ? UINT_MAX32 : static_cast<uint32>(tmp);
}

bool mark_unsupported_function(const char *where, void *store, uint result);

/* convenience helper for mark_unsupported_function() above */
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_type.h
Expand Up @@ -181,10 +181,10 @@ class DTCollation {


static inline uint32
char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg)
char_to_byte_length_safe(size_t char_length_arg, uint32 mbmaxlen_arg)
{
ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
return (tmp > UINT_MAX32) ? (uint32) UINT_MAX32 : (uint32) tmp;
ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
return tmp > UINT_MAX32 ? UINT_MAX32 : static_cast<uint32>(tmp);
}

/**
Expand Down

0 comments on commit 6a9e2e1

Please sign in to comment.