Skip to content

Commit

Permalink
Move thread_local variable out of function scope.
Browse files Browse the repository at this point in the history
MinGW seems to have a bug with function-local thread_local variables.
  • Loading branch information
Flamefire committed Dec 3, 2024
1 parent 2c9d89e commit b596ce2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cstdlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ namespace nowide {
#include <vector>
#include <windows.h>

namespace {
thread_local boost::nowide::stackstring getenv_value;
}

namespace boost {
namespace nowide {
char* getenv(const char* key)
{
thread_local stackstring value;

const wshort_stackstring name(key);

static const size_t buf_size = 64;
Expand All @@ -72,8 +74,8 @@ namespace nowide {
return 0;
ptr = &tmp[0];
}
value.convert(ptr);
return value.get();
getenv_value.convert(ptr);
return getenv_value.get();
}

int setenv(const char* key, const char* value, int overwrite)
Expand Down

0 comments on commit b596ce2

Please sign in to comment.