Skip to content

Commit 7544fd4

Browse files
committed
fix problem of reallocated string
1 parent 3deac2e commit 7544fd4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

sql/filesort.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count,
634634
}
635635

636636
#ifndef DBUG_OFF
637+
638+
static char dbug_row_print_buf[4096];
639+
637640
/*
638641
Print table's current row into a buffer and return a pointer to it.
639642
@@ -649,11 +652,9 @@ static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count,
649652
const char* dbug_print_row(TABLE *table, const uchar *rec, bool print_names)
650653
{
651654
Field **pfield;
652-
const size_t alloc_size= 512;
653-
char *row_buff= (char *) alloc_root(&table->mem_root, alloc_size);
654-
char *row_buff_tmp= (char *) alloc_root(&table->mem_root, alloc_size);
655-
String tmp(row_buff_tmp, alloc_size, &my_charset_bin);
656-
String output(row_buff, alloc_size, &my_charset_bin);
655+
char row_buff_tmp[512];
656+
String tmp(row_buff_tmp, sizeof(row_buff_tmp), &my_charset_bin);
657+
String output(dbug_row_print_buf, sizeof(dbug_row_print_buf), &my_charset_bin);
657658

658659
auto move_back_lambda= [table, rec]() mutable {
659660
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)
717718
}
718719
}
719720
output.append(")");
720-
721-
return output.c_ptr_safe();
721+
if (output.c_ptr() == dbug_row_print_buf)
722+
return dbug_row_print_buf;
723+
else
724+
return "Couldn't fit into buffer";
722725
}
723726

724727

0 commit comments

Comments
 (0)