From 7544fd4caeb959bdb573a4b09fbfa225a1ab37a6 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 20 Feb 2025 00:06:09 +0100 Subject: [PATCH] fix problem of reallocated string --- sql/filesort.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sql/filesort.cc b/sql/filesort.cc index af03067257c..a0e16791f89 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -634,6 +634,9 @@ static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count, } #ifndef DBUG_OFF + +static char dbug_row_print_buf[4096]; + /* Print table's current row into a buffer and return a pointer to it. @@ -649,11 +652,9 @@ static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count, const char* dbug_print_row(TABLE *table, const uchar *rec, bool print_names) { Field **pfield; - const size_t alloc_size= 512; - char *row_buff= (char *) alloc_root(&table->mem_root, alloc_size); - char *row_buff_tmp= (char *) alloc_root(&table->mem_root, alloc_size); - String tmp(row_buff_tmp, alloc_size, &my_charset_bin); - String output(row_buff, alloc_size, &my_charset_bin); + char row_buff_tmp[512]; + String tmp(row_buff_tmp, sizeof(row_buff_tmp), &my_charset_bin); + String output(dbug_row_print_buf, sizeof(dbug_row_print_buf), &my_charset_bin); auto move_back_lambda= [table, rec]() mutable { table->move_fields(table->field, table->record[0], rec); @@ -717,8 +718,10 @@ const char* dbug_print_row(TABLE *table, const uchar *rec, bool print_names) } } output.append(")"); - - return output.c_ptr_safe(); + if (output.c_ptr() == dbug_row_print_buf) + return dbug_row_print_buf; + else + return "Couldn't fit into buffer"; }