TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25373 20
PSA - Do not assign the result of ::getenv to a std::string

This is a lesson I apparently have to learn repeatedly. Many, many times. Way too many times.

Unit tests are failing, I'm too ADD to actually read the error message for comprehension, fart around changing things to try to find why the exception is being thrown, then spontaneously remember "oh, yeah, ::getenv will return NULL if the variable hasn't been defined, and assigning a NULL to a std::string is Bad Juju.

Wasted a whole day on this nonsense.

I know this. I have known this for years, and I still make this mistake.

Blah. Needed to vent.

https://redd.it/1tx3eb6
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Sep 29, 2026Boost.Graph 1.95 will be C++17 Dear Boost.Graph community, In two release cycles (Boost re…
  2. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  3. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  4. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  5. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  6. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →