the code will compile, and work quite well, but it is technically undefined behavior. You can allocate the appropriate memory with an expression that is unlikely to have off-by-one errors:
so even though the latter code is not allowed and/or is undefined behavior my program will still work as I intend it to do?
Or will it cause some memory leak down the road?
If I read the SO thread correctly, your lower example violates the C++ standard but should work fine with gcc/g++ as a compiler anyway. So unless you're worried about using another compiler in the future, you'll probably be fine.