summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-10-16 12:08:20 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-10-16 12:08:20 +0200
commit2f2234102e450b5828d2633d2512d94f212a4362 (patch)
treef8fa9c4ff99ff7f5a93d9c6cd3efe1d2ac11f1a6 /sal/osl
parent13b596e29e5b2e2ab5e43f147db6638a856c52a6 (diff)
Rephrase checks for exceeding off_t limits
...in a way that, by using a function template, avoids new Clang 6 -Werror,-Wtautological-constant-compare when sal_Int64 and off_t are the same type. Change-Id: I06d4feb8ba8cb163e5208f107c28959755ff5633
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/unx/file.cxx21
1 files changed, 11 insertions, 10 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 5f723dd9a2d3..1a3259c654e7 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -1146,6 +1146,12 @@ oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle)
const off_t MAX_OFF_T = std::numeric_limits< off_t >::max();
+namespace {
+
+template<typename T> bool exceedsOffT(T n) { return n > MAX_OFF_T; }
+
+}
+
oslFileError SAL_CALL osl_mapFile(
oslFileHandle Handle,
void** ppAddr,
@@ -1166,8 +1172,7 @@ oslFileError SAL_CALL osl_mapFile(
size_t const nLength = sal::static_int_cast< size_t >(uLength);
- sal_uInt64 const limit_off_t = MAX_OFF_T;
- if (uOffset > limit_off_t)
+ if (exceedsOffT(uOffset))
return osl_File_E_OVERFLOW;
if (pImpl->m_kind == FileHandle_Impl::KIND_MEM)
@@ -1371,8 +1376,7 @@ oslFileError SAL_CALL osl_readFileAt(
if ((pImpl->m_state & FileHandle_Impl::STATE_SEEKABLE) == 0)
return osl_File_E_SPIPE;
- sal_uInt64 const limit_off_t = MAX_OFF_T;
- if (uOffset > limit_off_t)
+ if (exceedsOffT(uOffset))
return osl_File_E_OVERFLOW;
off_t const nOffset = sal::static_int_cast< off_t >(uOffset);
@@ -1407,8 +1411,7 @@ oslFileError SAL_CALL osl_writeFileAt(
if ((pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE) == 0)
return osl_File_E_BADF;
- sal_uInt64 const limit_off_t = MAX_OFF_T;
- if (limit_off_t < uOffset)
+ if (exceedsOffT(uOffset))
return osl_File_E_OVERFLOW;
off_t const nOffset = sal::static_int_cast< off_t >(uOffset);
@@ -1458,8 +1461,7 @@ oslFileError SAL_CALL osl_setFilePos(oslFileHandle Handle, sal_uInt32 uHow, sal_
if ((!pImpl) || ((pImpl->m_kind == FileHandle_Impl::KIND_FD) && (pImpl->m_fd == -1)))
return osl_File_E_INVAL;
- sal_Int64 const limit_off_t = MAX_OFF_T;
- if (uOffset > limit_off_t)
+ if (exceedsOffT(uOffset))
return osl_File_E_OVERFLOW;
off_t nPos = 0, nOffset = sal::static_int_cast< off_t >(uOffset);
@@ -1522,8 +1524,7 @@ oslFileError SAL_CALL osl_setFileSize(oslFileHandle Handle, sal_uInt64 uSize)
if ((pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE) == 0)
return osl_File_E_BADF;
- sal_uInt64 const limit_off_t = MAX_OFF_T;
- if (uSize > limit_off_t)
+ if (exceedsOffT(uSize))
return osl_File_E_OVERFLOW;
oslFileError result = pImpl->syncFile();