[MDEV-9465] The constructor StringBuffer(const char *str, size_t length, const CHARSET_INFO *cs) looks suspicious Created: 2016-01-26  Updated: 2019-04-23  Resolved: 2019-04-23

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.1
Fix Version/s: 10.1.39

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


 Description   

The second StringBuffer constructor looks suspicious:

  StringBuffer(const char *str, size_t length, const CHARSET_INFO *cs)
    : String(buff, buff_sz, cs)
  {
    set(str, length, cs);
  }

It calls this String() constructor:

  String(char *str,uint32 len, CHARSET_INFO *cs)
  { 
    Ptr=(char*) str; Alloced_length=str_length=len; extra_alloc= 0;
    alloced= thread_specific= 0;
    str_charset=cs;
  }

and then calls this set():

  inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs)
  {
    free();
    Ptr=(char*) str; str_length=arg_length;
    str_charset=cs;
  }

So "ptr" does not point to StringBuffer::buff any more. This call sequence seems to have a very little sense. Perhaps it should be copy() instead of set().


Generated at Thu Feb 08 07:34:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.