Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/10.3' into 10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
montywi committed Jul 2, 2020
2 parents f347b3e + b6ec1e8 commit 5211af1
Show file tree
Hide file tree
Showing 39 changed files with 165 additions and 180 deletions.
4 changes: 2 additions & 2 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10126,7 +10126,7 @@ void append_replace_regex(char* expr, char *expr_end, struct st_replace_regex* r
/* Allow variable for the *entire* list of replacements */
if (*p == '$')
{
const char *v_end;
const char *v_end= 0;
VAR *val= var_get(p, &v_end, 0, 1);

if (val)
Expand Down Expand Up @@ -10767,7 +10767,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
for (i=1 ; i <= found_sets ; i++)
{
pos=from[found_set[i-1].table_offset];
rep_str[i].found= !memcmp(pos, "\\^", 3) ? 2 : 1;
rep_str[i].found= !strncmp(pos, "\\^", 3) ? 2 : 1;
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
Expand Down
2 changes: 2 additions & 0 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ static inline int my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count)

static inline int my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count)
{
MEM_CHECK_DEFINED(Buffer, Count);
if (info->write_pos + Count <= info->write_end)
{
memcpy(info->write_pos, Buffer, Count);
Expand All @@ -555,6 +556,7 @@ static inline int my_b_get(IO_CACHE *info)

static inline my_bool my_b_write_byte(IO_CACHE *info, uchar chr)
{
MEM_CHECK_DEFINED(&chr, 1);
if (info->write_pos >= info->write_end)
if (my_b_flush_io_cache(info, 1))
return 1;
Expand Down
67 changes: 35 additions & 32 deletions include/my_valgrind.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
# define __SANITIZE_ADDRESS__ 1
#endif

#ifdef HAVE_valgrind
#define IF_VALGRIND(A,B) A
#else
#define IF_VALGRIND(A,B) B
#endif

#if defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
#if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# define HAVE_valgrind
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
# define MEM_MAKE_ADDRESSABLE(a,len) MEM_UNDEFINED(a,len)
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) __msan_check_mem_is_initialized(a,len)
# define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len)
# define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len)
# define REDZONE_SIZE 8
#elif defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
# include <valgrind/memcheck.h>
# define HAVE_valgrind_or_MSAN
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
# define MEM_MAKE_ADDRESSABLE(a,len) MEM_UNDEFINED(a,len)
# define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len)
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
Expand All @@ -45,53 +51,50 @@
# include <sanitizer/asan_interface.h>
/* How to do manual poisoning:
https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */
# define MEM_UNDEFINED(a,len) ASAN_UNPOISON_MEMORY_REGION(a,len)
# define MEM_UNDEFINED(a,len) ((void) 0)
# define MEM_MAKE_ADDRESSABLE(a,len) ASAN_UNPOISON_MEMORY_REGION(a,len)
# define MEM_MAKE_DEFINED(a,len) ((void) 0)
# define MEM_NOACCESS(a,len) ASAN_POISON_MEMORY_REGION(a,len)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) \
assert(!__asan_region_is_poisoned((void*) a,len))
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
# define MEM_GET_VBITS(a,b,len) ((void) 0)
# define MEM_SET_VBITS(a,b,len) ((void) 0)
# define REDZONE_SIZE 8
#elif __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# define HAVE_valgrind_or_MSAN
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) __msan_check_mem_is_initialized(a,len)
# define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len)
# define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len)
# define REDZONE_SIZE 8
#else
# define MEM_UNDEFINED(a,len) ((void) (a), (void) (len))
# define MEM_UNDEFINED(a,len) ((void) 0)
# define MEM_MAKE_ADDRESSABLE(a,len) ((void) 0)
# define MEM_MAKE_DEFINED(a,len) ((void) 0)
# define MEM_NOACCESS(a,len) ((void) 0)
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
# define MEM_CHECK_DEFINED(a,len) ((void) 0)
# define MEM_GET_VBITS(a,b,len) ((void) 0)
# define MEM_SET_VBITS(a,b,len) ((void) 0)
# define REDZONE_SIZE 0
#endif /* HAVE_VALGRIND_MEMCHECK_H */
#endif /* __has_feature(memory_sanitizer) */

#ifdef HAVE_valgrind
#define IF_VALGRIND(A,B) A
#else
#define IF_VALGRIND(A,B) B
#endif

#ifdef TRASH_FREED_MEMORY
/*
TRASH_FILL() has to call MEM_UNDEFINED() to cancel any effect of TRASH_FREE().
_TRASH_FILL() has to call MEM_MAKE_ADDRESSABLE() to cancel any effect of
TRASH_FREE().
This can happen in the case one does
TRASH_ALLOC(A,B) ; TRASH_FREE(A,B) ; TRASH_ALLOC(A,B)
to reuse the same memory in an internal memory allocator like MEM_ROOT.
For my_malloc() and safemalloc() the extra MEM_UNDEFINED is bit of an
overkill.
TRASH_FILL() is an internal function and should not be used externally.
_TRASH_FILL() is an internal function and should not be used externally.
*/
#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
#define _TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_MAKE_ADDRESSABLE(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
#else
#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0)
#define _TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0)
#endif
/** Note that some memory became allocated or uninitialized. */
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
/** Note that some memory became allocated and/or uninitialized. */
#define TRASH_ALLOC(A,B) do { _TRASH_FILL(A,B,0xA5); MEM_MAKE_ADDRESSABLE(A,B); } while(0)
/** Note that some memory became freed. (Prohibit further access to it.) */
#define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)
#define TRASH_FREE(A,B) do { _TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)

#endif /* MY_VALGRIND_INCLUDED */
4 changes: 2 additions & 2 deletions mysql-test/main/sp-big.result
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be
insert t1 select seq, seq, 1, 1, seq, seq, seq from seq_1_to_2000;
set @before=unix_timestamp();
call select_test();
select unix_timestamp() - @before < 60;
unix_timestamp() - @before < 60
select unix_timestamp() - @before < @time;
unix_timestamp() - @before < @time
1
drop procedure select_test;
drop table t1;
13 changes: 12 additions & 1 deletion mysql-test/main/sp-big.test
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ delimiter ;//
insert t1 select seq, seq, 1, 1, seq, seq, seq from seq_1_to_2000;
set @before=unix_timestamp();
call select_test();
select unix_timestamp() - @before < 60;

--let $time=60
if ($VALGRIND_TEST)
{
--let $time=600
}

--disable_query_log
--eval set @time=$time;
--enable_query_log

select unix_timestamp() - @before < @time;
drop procedure select_test;
drop table t1;
2 changes: 1 addition & 1 deletion mysys/my_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
uchar* point;
reg1 USED_MEM *next= 0;
reg2 USED_MEM **prev;
size_t original_length = length;
size_t original_length __attribute__((unused)) = length;
DBUG_ENTER("alloc_root");
DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name));
DBUG_ASSERT(alloc_root_inited(mem_root));
Expand Down
13 changes: 12 additions & 1 deletion sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7647,6 +7647,17 @@ int Field_varstring::save_field_metadata(uchar *metadata_ptr)
return 2;
}


bool Field_varstring::memcpy_field_possible(const Field *from) const
{
return (Field_str::memcpy_field_possible(from) &&
!compression_method() == !from->compression_method() &&
length_bytes == ((Field_varstring*) from)->length_bytes &&
(table->file && !(table->file->ha_table_flags() &
HA_RECORD_MUST_BE_CLEAN_ON_WRITE)));
}


int Field_varstring::store(const char *from,size_t length,CHARSET_INFO *cs)
{
DBUG_ASSERT(marked_for_write_or_computed());
Expand Down Expand Up @@ -7709,7 +7720,7 @@ my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
}


#ifdef HAVE_valgrind_or_MSAN
#ifdef HAVE_valgrind
void Field_varstring::mark_unused_memory_as_defined()
{
uint used_length= get_length();
Expand Down
11 changes: 3 additions & 8 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ class Field: public Value_source
return store(ls.str, (uint) ls.length, cs);
}

#ifdef HAVE_valgrind_or_MSAN
#ifdef HAVE_valgrind
/**
Mark unused memory in the field as defined. Mainly used to ensure
that if we write full field to disk (for example in
Expand Down Expand Up @@ -3692,15 +3692,10 @@ class Field_varstring :public Field_longstr {
length_bytes : 0);
}
Copy_func *get_copy_func(const Field *from) const;
bool memcpy_field_possible(const Field *from) const
{
return Field_str::memcpy_field_possible(from) &&
!compression_method() == !from->compression_method() &&
length_bytes == ((Field_varstring*) from)->length_bytes;
}
bool memcpy_field_possible(const Field *from) const;
int store(const char *to,size_t length,CHARSET_INFO *charset);
using Field_str::store;
#ifdef HAVE_valgrind_or_MSAN
#ifdef HAVE_valgrind
void mark_unused_memory_as_defined();
#endif
double val_real(void);
Expand Down
2 changes: 1 addition & 1 deletion sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ register_query_cache_dependant_tables(THD *thd,
sub_elem= subpart_it++;
part= i * num_subparts + j;
/* we store the end \0 as part of the key */
end= strmov(engine_pos, sub_elem->partition_name);
end= strmov(engine_pos, sub_elem->partition_name) + 1;
length= (uint)(end - engine_key);
/* Copy the suffix also to query cache key */
memcpy(query_cache_key_end, engine_key_end, (end - engine_key_end));
Expand Down
3 changes: 2 additions & 1 deletion sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ enum enum_alter_inplace_result {
#define HA_HAS_NEW_CHECKSUM (1ULL << 38)
#define HA_CAN_VIRTUAL_COLUMNS (1ULL << 39)
#define HA_MRR_CANT_SORT (1ULL << 40)
#define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (1ULL << 41) /* unused */
/* All of VARCHAR is stored, including bytes after real varchar data */
#define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (1ULL << 41)

/*
This storage engine supports condition pushdown
Expand Down
2 changes: 1 addition & 1 deletion sql/item_subselect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ bool Item_subselect::exec()

push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_UNKNOWN_ERROR, "DBUG: Item_subselect::exec %.*s",
print.length(),print.c_ptr());
print.length(),print.ptr());
);
/*
Do not execute subselect in case of a fatal error
Expand Down
14 changes: 5 additions & 9 deletions sql/session_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,12 @@ bool Session_sysvars_tracker::enable(THD *thd)
bool Session_sysvars_tracker::update(THD *thd, set_var *var)
{
vars_list tool_list;
void *copy;
size_t length= 1;

if (var->save_result.string_value.str)
copy= my_memdup(var->save_result.string_value.str,
(length= var->save_result.string_value.length + 1),
MYF(MY_WME | MY_THREAD_SPECIFIC));
else
copy= my_strdup("", MYF(MY_WME | MY_THREAD_SPECIFIC));

void *copy= var->save_result.string_value.str ?
my_memdup(var->save_result.string_value.str,
(length= var->save_result.string_value.length + 1),
MYF(MY_WME | MY_THREAD_SPECIFIC)) :
my_strdup("", MYF(MY_WME | MY_THREAD_SPECIFIC));
if (!copy)
return true;

Expand Down
Loading

0 comments on commit 5211af1

Please sign in to comment.