From c781c31638cc5ae06eb325567323f131e8183a75 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Sep 2005 21:03:45 +0000 Subject: [PATCH] added wx_truncate_cast and use it (sometimes instead of wx_static_cast) to explicitely show int truncation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35539 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 7 +++++++ src/common/regex.cpp | 5 +++-- src/common/sstream.cpp | 5 +++-- src/unix/sound.cpp | 6 +++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index 2924970772..b18f62f9d5 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -292,6 +292,13 @@ typedef int wxWindowID; #define wx_reinterpret_cast(t, x) ((t)(x)) #endif +/* + This one is a wx invention: like static cast but used when we intentionally + truncate from a larger to smaller type, static_cast<> can't be used for it + as it results in warnings when using some compilers (SGI mipspro for example) + */ +#define wx_truncate_cast(t, x) ((t)(x)) + /* for consistency with wxStatic/DynamicCast defined in wx/object.h */ #define wxConstCast(obj, className) wx_const_cast(className *, obj) diff --git a/src/common/regex.cpp b/src/common/regex.cpp index 6f7d454e77..ac85aac972 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -316,10 +316,11 @@ bool wxRegExImpl::GetMatch(size_t *start, size_t *len, size_t index) const const regmatch_t& match = m_Matches[index]; + // we need the casts because rm_so can be a 64 bit quantity if ( start ) - *start = match.rm_so; + *start = wx_truncate_cast(size_t, match.rm_so); if ( len ) - *len = match.rm_eo - match.rm_so; + *len = wx_truncate_cast(size_t, match.rm_eo - match.rm_so); return true; } diff --git a/src/common/sstream.cpp b/src/common/sstream.cpp index 0e783fb640..8033dff28c 100644 --- a/src/common/sstream.cpp +++ b/src/common/sstream.cpp @@ -93,10 +93,11 @@ wxFileOffset wxStringInputStream::OnSysSeek(wxFileOffset ofs, wxSeekMode mode) return wxInvalidOffset; } - if ( ofs < 0 || wx_static_cast(size_t, ofs) > m_len ) + if ( ofs < 0 || ofs > wx_static_cast(wxFileOffset, m_len) ) return wxInvalidOffset; - m_pos = wx_static_cast(size_t, ofs); + // FIXME: this can't be right + m_pos = wx_truncate_cast(size_t, ofs); return ofs; } diff --git a/src/unix/sound.cpp b/src/unix/sound.cpp index 8ef528b489..3871409e7e 100644 --- a/src/unix/sound.cpp +++ b/src/unix/sound.cpp @@ -465,7 +465,11 @@ bool wxSound::Create(const wxString& fileName, bool isResource) return false; } - wxFileOffset len = fileWave.Length(); + wxFileOffset lenOrig = fileWave.Length(); + if ( lenOrig == wxInvalidOffset ) + return false; + + size_t len = wx_truncate_cast(size_t, lenOrig); wxUint8 *data = new wxUint8[len]; if (fileWave.Read(data, len) != len) { -- 2.45.2