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 | 35dad3581b2f1c6c7db997eeb110819d0521a589 (patch) | |
tree | 51e1514947a539bbb7ec1ebfa711c6c1d55d16b2 | |
parent | cd62d5130a7153dace21b2acccd4fcfc6984b508 (diff) | |
download | openttd-35dad3581b2f1c6c7db997eeb110819d0521a589.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)
-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; |