← Back to team overview

maria-developers team mailing list archive

Re: Use of std::string

 

Hi, Vicențiu!

On Jan 05, Vicențiu Ciorbaru wrote:
> 
> Sample code where we can avoid ifs:
> 
>     case SSL_TYPE_SPECIFIED:
>       table->field[next_field]->store(STRING_WITH_LEN("SPECIFIED"),
>                                       &my_charset_latin1);
>       table->field[next_field+1]->store("", 0, &my_charset_latin1);
>       table->field[next_field+2]->store("", 0, &my_charset_latin1);
>       table->field[next_field+3]->store("", 0, &my_charset_latin1);
>       if (lex->ssl_cipher)
>         table->field[next_field+1]->store(lex->ssl_cipher,
>                                           strlen(lex->ssl_cipher),
>                                           system_charset_info);
>       if (lex->x509_issuer)
>         table->field[next_field+2]->store(lex->x509_issuer,
>                                           strlen(lex->x509_issuer),
>                                           system_charset_info);
>       if (lex->x509_subject)
>         table->field[next_field+3]->store(lex->x509_subject,
>                                           strlen(lex->x509_subject),
>                                           system_charset_info);
> 
> This just becomes:
>     case SSL_TYPE_SPECIFIED:
>       table->field[next_field]->store(STRING_WITH_LEN("SPECIFIED"), &my_charset_latin1);
>       table->field[next_field+1]->store(ssl_cipher.c_str(), ssl_cipher.size(), &my_charset_latin1);
>       table->field[next_field+2]->store(x509_issuer.c_str(), x509_issuer.size(), &my_charset_latin1);
>       table->field[next_field+3]->store(x509_subject.c_str(), x509_subject.size(), &my_charset_latin1);
> 
> Thoughts?

I can immediately think of two more approaches:

 1. using String class (sql/sql_string.h)
 2. using safe_str helper:

   table->field[next_field+1]->store(safe_str(lex->ssl_cipher),
                                     safe_strlen(lex->ssl_cipher),
                                     &my_charset_latin1);


As for std:string - currently the server code uses these approaches to
storing strings: char*, LEX_STRING, DYNAMIC_STRING, CSET_STRING, String.
With variations like uchar*, LEX_CSTRING, LEX_CUSTRING, StringBuffer,
may be more.

I don't particularly like an idea of adding yes another alternative into
this mess without a clear rule of what to use where.

So, could you say when should one use std::string and when one should
stick to one of the existing types?

Regards,
Sergei
Chief Architect MariaDB
and security@xxxxxxxxxxx
-- 
Vote for my Percona Live 2016 talks:
https://www.percona.com/live/data-performance-conference-2016/sessions/mariadb-connectors-fast-and-smart-new-protocol-optimizations#community-voting
https://www.percona.com/live/data-performance-conference-2016/sessions/mariadb-101-security-validation-authentication-encryption#community-voting


Follow ups

References