Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / StdStrBuf question
- - By Newton [th] Date 2013-12-08 07:13
Will this

const char* C4TimeMilliseconds::AsString() const
{
  StdStrBuf string;
  string.Format("%u:%02u:%02u:%03u:",time / 1000 / 60 / 60, (time / 1000 / 60) % 60, (time / 1000) % 60, time % 1000);
  return string.getData();
}


result in an invalid memory error?

As far as I understand StdStrBuf, it creates a pointer for the char data and cleans it up in the destructor. So, the destructor is already called after return, thus the method returns a pointer to invalid memory? If I am right, how to solve this?
Parent - By Clonk-Karl [de] Date 2013-12-08 13:03
Yes, it looks like a memory error. I suggest returning a StdStrBuf (or a StdCopyStrBuf) to fix it.
Reply
Up Topic Development / Developer's Corner / StdStrBuf question

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill