Skip to content

Commit c06a305

Browse files
author
Alexander Nozdrin
committed
Backporting revision from mysql-6.0-codebase-bugfixing.
Original revision: ------------------------------------------------------------ revno: 3789.1.9 revision-id: [email protected] parent: [email protected] committer: Sergei Golubchik <[email protected]> branch nick: 6.0-codebase timestamp: Tue 2009-12-29 14:44:48 +0100 message: better fix for Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds use setenv instead of putenv ------------------------------------------------------------
1 parent 7973ab7 commit c06a305

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

client/mysqltest.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
#define QUERY_SEND_FLAG 1
7373
#define QUERY_REAP_FLAG 2
7474

75+
#ifndef HAVE_SETENV
76+
#error implement our portable setenv replacement in mysys
77+
#endif
78+
7579
enum {
7680
OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
7781
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
@@ -216,7 +220,6 @@ typedef struct
216220
int alloced_len;
217221
int int_dirty; /* do not update string if int is updated until first read */
218222
int alloced;
219-
char *env_s;
220223
} VAR;
221224

222225
/*Perl/shell-like variable registers */
@@ -1941,7 +1944,6 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val,
19411944
tmp_var->alloced_len = val_alloc_len;
19421945
tmp_var->int_val = (val) ? atoi(val) : 0;
19431946
tmp_var->int_dirty = 0;
1944-
tmp_var->env_s = 0;
19451947
return tmp_var;
19461948
}
19471949

@@ -2069,20 +2071,18 @@ void var_set(const char *var_name, const char *var_name_end,
20692071

20702072
if (env_var)
20712073
{
2072-
char buf[1024], *old_env_s= v->env_s;
20732074
if (v->int_dirty)
20742075
{
20752076
sprintf(v->str_val, "%d", v->int_val);
20762077
v->int_dirty= 0;
20772078
v->str_val_len= strlen(v->str_val);
20782079
}
2079-
my_snprintf(buf, sizeof(buf), "%.*s=%.*s",
2080-
v->name_len, v->name,
2081-
v->str_val_len, v->str_val);
2082-
if (!(v->env_s= my_strdup(buf, MYF(MY_WME))))
2083-
die("Out of memory");
2084-
putenv(v->env_s);
2085-
my_free(old_env_s, MYF(MY_ALLOW_ZERO_PTR));
2080+
char oldc= v->name[v->name_len];
2081+
if (oldc)
2082+
v->name[v->name_len]= 0; // setenv() expects \0-terminated strings
2083+
setenv(v->name, v->str_val, 1); // v->str_val is always \0-terminated
2084+
if (oldc)
2085+
v->name[v->name_len]= oldc;
20862086
}
20872087
DBUG_VOID_RETURN;
20882088
}

include/config-win.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,12 @@ inline ulonglong double2ulonglong(double d)
318318
#define strcasecmp stricmp
319319
#define strncasecmp strnicmp
320320

321-
#define HAVE_SNPRINTF /* Gave link error */
321+
#define HAVE_SNPRINTF 1
322322
#define snprintf _snprintf
323323

324+
#define HAVE_SETENV 1
325+
#define setenv(VAR,VAL,X) _putenv_s(VAR,VAL)
326+
324327
#ifdef _MSC_VER
325328
#define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */
326329
#define HAVE_ANSI_INCLUDE

0 commit comments

Comments
 (0)