This is my code
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
char *var = "TEST=/usr/home";
putenv(var);
cout<<getenv("TEST")<<endl; // This works
var[0]= 'A'; // Crashes as soon as this runs
cout<<getenv("AEST")<<endl;
return 0;
}
Output is
/usr/home
zsh: bus error ./t
If i understand correctly, this var pointer will become part of environmnet itself, so if i update this variable, the getenv should also give me updated stuff
But instead it crashes in mac.
Results in Macbook = It crashes with bus error
Results in Linux = No crash and no output as well, seems like that line is completely just ignored