|
72 | 72 | #define QUERY_SEND_FLAG 1
|
73 | 73 | #define QUERY_REAP_FLAG 2
|
74 | 74 |
|
| 75 | +#ifndef HAVE_SETENV |
| 76 | +#error implement our portable setenv replacement in mysys |
| 77 | +#endif |
| 78 | + |
75 | 79 | enum {
|
76 | 80 | OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
|
77 | 81 | OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
|
@@ -216,7 +220,6 @@ typedef struct
|
216 | 220 | int alloced_len;
|
217 | 221 | int int_dirty; /* do not update string if int is updated until first read */
|
218 | 222 | int alloced;
|
219 |
| - char *env_s; |
220 | 223 | } VAR;
|
221 | 224 |
|
222 | 225 | /*Perl/shell-like variable registers */
|
@@ -1941,7 +1944,6 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val,
|
1941 | 1944 | tmp_var->alloced_len = val_alloc_len;
|
1942 | 1945 | tmp_var->int_val = (val) ? atoi(val) : 0;
|
1943 | 1946 | tmp_var->int_dirty = 0;
|
1944 |
| - tmp_var->env_s = 0; |
1945 | 1947 | return tmp_var;
|
1946 | 1948 | }
|
1947 | 1949 |
|
@@ -2069,20 +2071,18 @@ void var_set(const char *var_name, const char *var_name_end,
|
2069 | 2071 |
|
2070 | 2072 | if (env_var)
|
2071 | 2073 | {
|
2072 |
| - char buf[1024], *old_env_s= v->env_s; |
2073 | 2074 | if (v->int_dirty)
|
2074 | 2075 | {
|
2075 | 2076 | sprintf(v->str_val, "%d", v->int_val);
|
2076 | 2077 | v->int_dirty= 0;
|
2077 | 2078 | v->str_val_len= strlen(v->str_val);
|
2078 | 2079 | }
|
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; |
2086 | 2086 | }
|
2087 | 2087 | DBUG_VOID_RETURN;
|
2088 | 2088 | }
|
|
0 commit comments