diff options
author | KUDr <kudr@openttd.org> | 2007-07-04 02:35:40 +0000 |
---|---|---|
committer | KUDr <kudr@openttd.org> | 2007-07-04 02:35:40 +0000 |
commit | 1d5b84d808c309f7341ae471dd1a39d0eae57cfa (patch) | |
tree | 51e1514947a539bbb7ec1ebfa711c6c1d55d16b2 /src/misc | |
parent | a85d72c60d0b430f406245674a922e2a852a9165 (diff) | |
download | openttd-1d5b84d808c309f7341ae471dd1a39d0eae57cfa.tar.xz |
(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)
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/str.hpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/misc/str.hpp b/src/misc/str.hpp index 72c9a2733..22276cb9d 100644 --- a/src/misc/str.hpp +++ b/src/misc/str.hpp @@ -120,18 +120,32 @@ struct CStrT : public CBlobT<Tchar> { 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; |