Skip to content

Commit dae1a49

Browse files
committed
Backport CONC-805 to 3.3: Fix C23/glibc 2.43 const-correctness errors
1 parent 7564026 commit dae1a49

1 file changed

Lines changed: 67 additions & 52 deletions

File tree

libmariadb/mariadb_lib.c

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -787,63 +787,78 @@ static void options_add_initcommand(struct st_mysql_options *options,
787787
if (ma_insert_dynamic(options->init_command, (gptr)&insert))
788788
free(insert);
789789
}
790+
790791
my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value)
791792
{
792-
if (config_option)
793-
{
794-
int i;
795-
char *c;
796-
797-
/* CONC-395: replace underscore "_" by dash "-" */
798-
while ((c= strchr(config_option, '_')))
799-
*c= '-';
800-
801-
for (i=0; mariadb_defaults[i].conf_key; i++)
793+
if (config_option)
802794
{
803-
if (!strcmp(mariadb_defaults[i].conf_key, config_option))
804-
{
805-
my_bool val_bool;
806-
int val_int;
807-
size_t val_sizet;
808-
int rc;
809-
void *option_val= NULL;
810-
switch (mariadb_defaults[i].type) {
811-
case MARIADB_OPTION_FUNC:
812-
return mariadb_defaults[i].u.option_func(mysql, config_option, config_value, -1);
813-
case MARIADB_OPTION_BOOL:
814-
val_bool= 0;
815-
if (config_value)
816-
val_bool= atoi(config_value);
817-
option_val= &val_bool;
818-
break;
819-
case MARIADB_OPTION_INT:
820-
val_int= 0;
821-
if (config_value)
822-
val_int= atoi(config_value);
823-
option_val= &val_int;
824-
break;
825-
case MARIADB_OPTION_SIZET:
826-
val_sizet= 0;
827-
if (config_value)
828-
val_sizet= strtol(config_value, NULL, 10);
829-
option_val= &val_sizet;
830-
break;
831-
case MARIADB_OPTION_STR:
832-
if (config_value && !config_value[0])
833-
option_val= NULL;
834-
else
835-
option_val= (void*)config_value;
836-
break;
837-
case MARIADB_OPTION_NONE:
838-
break;
795+
int i;
796+
char *c;
797+
char *mutable_option = strdup(config_option);
798+
799+
if (!mutable_option)
800+
return 1;
801+
802+
/* CONC-395: replace underscore "_" by dash "-" */
803+
while ((c = strchr(mutable_option, '_')))
804+
*c = '-';
805+
806+
for (i = 0; mariadb_defaults[i].conf_key; i++)
807+
{
808+
if (!strcmp(mariadb_defaults[i].conf_key, mutable_option))
809+
{
810+
my_bool val_bool;
811+
int val_int;
812+
size_t val_sizet;
813+
int rc;
814+
void *option_val = NULL;
815+
816+
switch (mariadb_defaults[i].type) {
817+
case MARIADB_OPTION_FUNC:
818+
{
819+
int ret= mariadb_defaults[i].u.option_func(mysql, mutable_option, config_value, -1);
820+
free(mutable_option);
821+
return ret;
822+
}
823+
case MARIADB_OPTION_BOOL:
824+
val_bool = 0;
825+
if (config_value)
826+
val_bool = atoi(config_value);
827+
option_val = &val_bool;
828+
break;
829+
case MARIADB_OPTION_INT:
830+
val_int = 0;
831+
if (config_value)
832+
val_int = atoi(config_value);
833+
option_val = &val_int;
834+
break;
835+
case MARIADB_OPTION_SIZET:
836+
val_sizet = 0;
837+
if (config_value)
838+
val_sizet = strtol(config_value, NULL, 10);
839+
option_val = &val_sizet;
840+
break;
841+
case MARIADB_OPTION_STR:
842+
if (config_value && !config_value[0])
843+
option_val = NULL;
844+
else
845+
option_val = (void*)config_value;
846+
break;
847+
case MARIADB_OPTION_NONE:
848+
break;
849+
}
850+
851+
rc = mysql_optionsv(mysql, mariadb_defaults[i].u.option, option_val);
852+
free(mutable_option);
853+
return test(rc);
854+
}
839855
}
840-
rc= mysql_optionsv(mysql, mariadb_defaults[i].u.option, option_val);
841-
return(test(rc));
842-
}
856+
857+
free(mutable_option);
843858
}
844-
}
845-
/* unknown key */
846-
return 1;
859+
860+
/* unknown key */
861+
return 1;
847862
}
848863

849864
/**

0 commit comments

Comments
 (0)