Closed BullyWiiPlaza closed 4 years ago
you are printing a dangling pointer
xorstr_ is the same as xorstr(...).crypt_get() which returns a pointer to the internal buffer.
@JustasMasiulis Ah. So inlining the variable fixes it?
int main() {
std::cout << xorstr_("Hello, world!") << std::endl;
return EXIT_SUCCESS;
}
Now it works correctly. Damn. This is dangerous to accidentally mess up.
yeah, that would be how you would most commonly use it, although it's entirely possible to store it and use it multiple times
auto xs = xorstr("something);
puts(xs.crypt_get());
puts(xs.get());
With optimizations enabled using
gcc
version9.2.1
(-O3
flag) onUbuntu
the following code produces an incorrect output:Output:
� a6�2F���!%��E�E���
Decompiled:
In debug mode the code correctly outputs:
Hello, world!
Decompiled:
Interestingly, in
MSVC
it works fine either way.Decompiled debug build:
Decompiled release build: