|I question how you are determining it is wrong. You code does not demonstrate that.
You are declaring a data entity on the stack. Then you are RETURNING part of that data entity from the method.
That is ALWAYS wrong.
And I suspect that is your problem.
The calling code also uses the stack. And will reuse exactly the same memory as where you are attempting to put a value if it wants to. For example if you are calling a method to 'print' the returned value in some way. Thus overwriting it. And that would cause a "junk" value either now or in the future.