From e22de3a3f28416acf35f55c058c17504d2e6f3ab Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 2 Dec 2009 11:00:44 +0100 Subject: [PATCH] Bug #49130 Running mtr tests with valgrind and debug produces lots of warnings Use safe output formats for strings that are not null terminated. sql/item_func.cc: Use "%*.s" rather than "%s" format. sql/protocol.cc: Use "%*.s" rather than "%s" format. sql/sql_test.cc: Improve output from print_where() - output (nil) predicate if predicate is null - also output pointer value, for tracing of assignment and copying of predicates sql/sql_view.cc: Use "%*.s" rather than "%s" format. --- sql/item_func.cc | 2 +- sql/protocol.cc | 4 ++-- sql/sql_test.cc | 21 ++++++++++----------- sql/sql_view.cc | 3 ++- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sql/item_func.cc b/sql/item_func.cc index 455bc5568e3..883476369f2 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3127,7 +3127,7 @@ String *udf_handler::val_str(String *str,String *save_str) if (res == str->ptr()) { str->length(res_length); - DBUG_PRINT("exit", ("str: %s", str->ptr())); + DBUG_PRINT("exit", ("str: %*.s", (int) str->length(), str->ptr())); DBUG_RETURN(str); } save_str->set(res, res_length, str->charset()); diff --git a/sql/protocol.cc b/sql/protocol.cc index ced44a6e972..855a6842f1f 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1012,8 +1012,8 @@ bool Protocol_text::store(const char *from, size_t length, { CHARSET_INFO *tocs= this->thd->variables.character_set_results; #ifndef DBUG_OFF - DBUG_PRINT("info", ("Protocol_text::store field %u (%u): %s", field_pos, - field_count, from)); + DBUG_PRINT("info", ("Protocol_text::store field %u (%u): %*.s", + field_pos, field_count, (int) length, from)); DBUG_ASSERT(field_pos < field_count); DBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_DECIMAL || diff --git a/sql/sql_test.cc b/sql/sql_test.cc index d9beb77f546..f95d19f099e 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -55,19 +55,18 @@ static const char *lock_descriptions[] = void print_where(COND *cond,const char *info, enum_query_type query_type) { + char buff[256]; + String str(buff,(uint32) sizeof(buff), system_charset_info); + str.length(0); if (cond) - { - char buff[256]; - String str(buff,(uint32) sizeof(buff), system_charset_info); - str.length(0); cond->print(&str, query_type); - str.append('\0'); - DBUG_LOCK_FILE; - (void) fprintf(DBUG_FILE,"\nWHERE:(%s) ",info); - (void) fputs(str.ptr(),DBUG_FILE); - (void) fputc('\n',DBUG_FILE); - DBUG_UNLOCK_FILE; - } + str.append('\0'); + + DBUG_LOCK_FILE; + (void) fprintf(DBUG_FILE,"\nWHERE:(%s) %p ", info, cond); + (void) fputs(str.ptr(),DBUG_FILE); + (void) fputc('\n',DBUG_FILE); + DBUG_UNLOCK_FILE; } /* This is for debugging purposes */ diff --git a/sql/sql_view.cc b/sql/sql_view.cc index ebb0615f80e..f65c5dc54c1 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -819,7 +819,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, thd->variables.sql_mode|= sql_mode; } - DBUG_PRINT("info", ("View: %s", view_query.ptr())); + DBUG_PRINT("info", + ("View: %*.s", (int) view_query.length(), view_query.ptr())); /* fill structure */ view->source= thd->lex->create_view_select;