Mercurial > hg > openttd
changeset 7153:dce496e685e5 draft
(svn r10427) -Fix: snprintf behaves differently in gcc than in VC causing unreadable artifacts in output. Now CStrT::AddFormatL() should behave correctly also when compiled by gcc (Rubidium)
author | KUDr <KUDr@openttd.org> |
---|---|
date | Wed, 04 Jul 2007 02:35:40 +0000 |
parents | 70c7afefcca5 |
children | 0fbfd542a99e |
files | src/misc/str.hpp |
diffstat | 1 files changed, 20 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/misc/str.hpp +++ b/src/misc/str.hpp @@ -120,18 +120,32 @@ { bsize_t addSize = Api::StrLen(format); if (addSize < 16) addSize = 16; - addSize += addSize > 1; - int ret, err; - do { + addSize += addSize / 2; + int ret; + int err = 0; + for (;;) { Tchar *buf = MakeFreeSpace(addSize); ret = Api::SPrintFL(buf, base::GetReserve(), format, args); - addSize *= 2; + if (ret >= base::GetReserve()) { + /* Greater return than given count means needed buffer size. */ + addSize = ret + 1; + continue; + } + if (ret >= 0) { + /* success */ + break; + } err = errno; - } while(ret < 0 && (err == ERANGE || err == ENOENT || err == 0)); + if (err != ERANGE && err != ENOENT && err != 0) { + /* some strange failure */ + break; + } + /* small buffer (M$ implementation) */ + addSize *= 2; + } if (ret > 0) { GrowSizeNC(ret); } else { -// int err = errno; base::FixTail(); } return ret;