From cd7e6d8b53ac0f9eb75c928b91e941fe70b88d63 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Wed, 15 Mar 2017 21:26:39 +0530 Subject: [PATCH] MDEV-11645: archive.archive fails in buildbot with valgrind (Use of uninitialised value) The fix is about filling the space beyond the end of VARCHAR values with zeroes. VARCHAR NULLs already has its buffer filled with zeros. So when the VARCHAR fields are not NULL, then we explicitly fill the buffer with zeros. --- storage/archive/ha_archive.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 9d6d100c1b8..810c0fd9c4d 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -376,6 +376,27 @@ unsigned int ha_archive::pack_row_v1(uchar *record) uchar *pos; DBUG_ENTER("pack_row_v1"); memcpy(record_buffer->buffer, record, table->s->reclength); + + /* + The end of VARCHAR fields are filled with garbage,so here + we explicitly set the end of the VARCHAR fields with zeroes + */ + + for (Field** field= table->field; (*field) ; field++) + { + Field *fld= *field; + if (fld->type() == MYSQL_TYPE_VARCHAR) + { + if (!(fld->is_real_null(record - table->record[0]))) + { + ptrdiff_t start= (fld->ptr - table->record[0]); + Field_varstring *const field_var= (Field_varstring *)fld; + uint offset= field_var->data_length() + field_var->length_size(); + memset(record_buffer->buffer + start + offset, 0, + fld->field_length - offset + 1); + } + } + } pos= record_buffer->buffer + table->s->reclength; for (blob= table->s->blob_field, end= blob + table->s->blob_fields; blob != end; blob++)