[MDEV-19863] Add const to TYPELIB pointers Created: 2019-06-26  Updated: 2019-07-04  Resolved: 2019-06-26

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-19861 Add intfastructure to have ENUM colum... Closed

 Description   

In many places in the code, a const qualifier can be added to TYPELIB pointers:

Members:

  • Field_enum::typelib
  • Column_definition_attributes::interval
  • Create_field::save_interval
  • Item_type_holder::enum_set_typelib
  • Type_holder::m_typelib

Return values in methods returning a TYPELIB pointer:

  • Field::get_typelib()
  • Type_all_attributes::get_typelib()

Related method and function parameters getting a TYPELIB pointer should also be fixed accordingly.



 Comments   
Comment by Alexander Barkov [ 2019-07-04 ]

There was a bug in the patch. Fortunately ASAN found it.

This patch fixes the problem

- (uint *) thd->alloc(sizeof(uint) * field->interval->count+1);
+ (uint *) thd->alloc(sizeof(uint) * (field->interval->count+1));

Function pack_header() in unireg.cc

Comment by Alexander Barkov [ 2019-07-04 ]

Pushed a cleanup patch:

commit b3161bd99556dae6d27823e8572f822f1de8d137 (HEAD -> 10.5, origin/HEAD, origin/10.5)
Author: Alexander Barkov <bar@mariadb.com>
Date: Thu Jul 4 18:26:59 2019 +0400

A cleanup (to fix ASAN problem) for MDEV-19863 Add const to TYPELIB pointers

In this statement:

(uint *) thd->alloc(sizeof(uint) * field->interval->count+1);

parentheses around the '+' operator were missing. So too few memory
was allocated, which caused ASAN builds to fail on these tests:

innodb.innodb-ucs2
parts.part_ctype_utf32
main.mix2_myisam_ucs2
main.case
main.ctype_ucs
main.ctype_utf16
main.ctype_utf16_uca
main.ctype_utf16le

Fixed to a correct version with parentheses:

(uint *) thd->alloc(sizeof(uint) * (field->interval->count+1));

Generated at Thu Feb 08 08:54:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.