[PATCH v5 1/3] storage.dll16: Simplify operations in IStream16::Seek.
Zebediah Figura
z.figura12 at gmail.com
Mon Feb 13 12:18:04 CST 2017
v5: Simplify all branches to use QuadPart directly.
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/storage.dll16/storage.c | 68 ++++++++++++++++++++------------------------
1 file changed, 31 insertions(+), 37 deletions(-)
diff --git a/dlls/storage.dll16/storage.c b/dlls/storage.dll16/storage.c
index 74aa7f9..1e54935 100644
--- a/dlls/storage.dll16/storage.c
+++ b/dlls/storage.dll16/storage.c
@@ -1179,44 +1179,38 @@ ULONG CDECL IStream16_fnRelease(IStream16 *iface)
* Does not handle 64 bits
*/
HRESULT CDECL IStream16_fnSeek(IStream16 *iface, LARGE_INTEGER offset, DWORD whence,
- ULARGE_INTEGER *newpos)
+ ULARGE_INTEGER *newpos)
{
- IStream16Impl *This = impl_from_IStream16(iface);
- TRACE_(relay)("(%p)->([%d.%d],%d,%p)\n",This,offset.u.HighPart,offset.u.LowPart,whence,newpos);
-
- switch (whence) {
- /* unix SEEK_xx should be the same as win95 ones */
- case SEEK_SET:
- /* offset must be ==0 (<0 is invalid, and >0 cannot be handled
- * right now.
- */
- assert(offset.u.HighPart==0);
- This->offset.u.HighPart = offset.u.HighPart;
- This->offset.u.LowPart = offset.u.LowPart;
- break;
- case SEEK_CUR:
- if (offset.u.HighPart < 0) {
- /* FIXME: is this negation correct ? */
- offset.u.HighPart = -offset.u.HighPart;
- offset.u.LowPart = (0xffffffff ^ offset.u.LowPart)+1;
-
- assert(offset.u.HighPart==0);
- assert(This->offset.u.LowPart >= offset.u.LowPart);
- This->offset.u.LowPart -= offset.u.LowPart;
- } else {
- assert(offset.u.HighPart==0);
- This->offset.u.LowPart+= offset.u.LowPart;
- }
- break;
- case SEEK_END:
- assert(offset.u.HighPart==0);
- This->offset.u.LowPart = This->stde.pps_size-offset.u.LowPart;
- break;
- }
- if (This->offset.u.LowPart>This->stde.pps_size)
- This->offset.u.LowPart=This->stde.pps_size;
- if (newpos) *newpos = This->offset;
- return S_OK;
+ IStream16Impl *This = impl_from_IStream16(iface);
+ TRACE_(relay)("(%p)->([%d.%d],%d,%p)\n",This,offset.u.HighPart,offset.u.LowPart,whence,newpos);
+
+ switch (whence) {
+ /* unix SEEK_xx should be the same as win95 ones */
+ case SEEK_SET:
+ This->offset.QuadPart = offset.QuadPart;
+ break;
+ case SEEK_CUR:
+ if ((offset.QuadPart < 0 && -offset.QuadPart > This->offset.QuadPart) ||
+ (offset.QuadPart > 0 && -offset.QuadPart <= This->offset.QuadPart))
+ return STG_E_INVALIDFUNCTION;
+ This->offset.QuadPart += offset.QuadPart;
+ break;
+ case SEEK_END:
+ if (offset.QuadPart > This->stde.pps_size)
+ return STG_E_INVALIDFUNCTION;
+
+ This->offset.QuadPart = This->stde.pps_size-offset.QuadPart;
+ break;
+ }
+ /* offset must be ==0 (<0 is invalid, and >0 cannot be handled
+ * right now.
+ */
+ assert(This->offset.u.HighPart == 0);
+
+ if (This->offset.u.LowPart>This->stde.pps_size)
+ This->offset.u.LowPart=This->stde.pps_size;
+ if (newpos) *newpos = This->offset;
+ return S_OK;
}
/******************************************************************************
--
2.7.4
More information about the wine-patches
mailing list