Help fopen fails
#1
Brick 
Hey guys,

I've noticed strange error, fopen returns NULL after some successful attempts, so I don't get any file loaded.
I've tried to zero it, but no luck.
It's just
Code:
filePtr = fopen(str("%s/Debug/textures/%s", fs_path->string, filename), "rb");

'str' is
Code:
char* str( const char *msg, ... ) { va_list argptr; char text[1024]; va_start(argptr, msg); vsnprintf(text, sizeof(text), msg, argptr); va_end(argptr); return text; }

Here's what I got after some attempts
[Image: ce5a9e2dd128.png]
.. as you see first time it's fine, but for second time it returns '?' at the end. ( or 377/377/ and another gibrish stuff )
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#2
Code:
char* str( const char *msg, ... ) { va_list argptr; char text[1024]; va_start(argptr, msg); vsnprintf(text, sizeof(text), msg, argptr); va_end(argptr); return text; }

Returning the temporary variable 'text' is baaaaaaaaad. Allocate a buffer, make 'text' static, or use a buffer in the caller's stack frame.
[Image: b_560_95_1.png]
Reply

#3
(01-19-2014, 17:28)Nukem Wrote:
Code:
char* str( const char *msg, ... ) { va_list argptr; char text[1024]; va_start(argptr, msg); vsnprintf(text, sizeof(text), msg, argptr); va_end(argptr); return text; }

Returning the temporary variable 'text' is baaaaaaaaad. Allocate a buffer, make 'text' static, or use a buffer in the caller's stack frame.

Yeah that is no good, you're returning an array's pointer which has been created in the function's stack.
Reply

#4
Oh thanks, I will try.

Oh yeah, now it works better.
I've made it 'static char text[1024];' and also created char *buf, now it returns right things.
Thanks.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.