Skip to content

Instantly share code, notes, and snippets.

@Cloudef
Created November 7, 2011 10:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Cloudef/1344609 to your computer and use it in GitHub Desktop.
winmm/mmio: Add extra handling for unbuffered MMIO handles
From c877ba08ee19b8b5f38ea4f37ce345208d158eba Mon Sep 17 00:00:00 2001
From: Cloudef <mailRoxas@gmail.com>
Date: Sun, 6 Nov 2011 18:57:57 +0200
Subject: winmm/mmio: Add extra handling for unbuffered MMIO handles
On non buffered mmioSeek, set the lBufOffset accordingly.
On non buffered mmioRead, seek to beginning of the file and return 0 meaning that the file ended.
I don't know if this just reveals bad programming in application,
or that native winmm likes to try handle code when it's wrongly used..
Fixes crashing on unbuffered cases.
---
dlls/winmm/mmio.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c
index 8c49826..0d4f6f6 100644
--- a/dlls/winmm/mmio.c
+++ b/dlls/winmm/mmio.c
@@ -765,7 +765,13 @@ LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
/* unbuffered case first */
if (!wm->info.pchBuffer)
- return send_message(wm->ioProc, &wm->info, MMIOM_READ, (LPARAM)pch, cch, FALSE);
+ {
+ /* check end of file, should return always 0 or error */
+ if (wm->info.lDiskOffset + cch > wm->dwFileSize)
+ return send_message(wm->ioProc, &wm->info, MMIOM_SEEK, 0, SEEK_SET, FALSE);
+ else
+ return send_message(wm->ioProc, &wm->info, MMIOM_READ, (LPARAM)pch, cch, FALSE);
+ }
/* first try from current buffer */
if (wm->info.pchNext != wm->info.pchEndRead) {
@@ -869,6 +872,6 @@ LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
/* not buffered, direct seek on file */
if (!wm->info.pchBuffer)
- return send_message(wm->ioProc, &wm->info, MMIOM_SEEK, lOffset, iOrigin, FALSE);
+ return wm->info.lBufOffset = send_message(wm->ioProc, &wm->info, MMIOM_SEEK, lOffset, iOrigin, FALSE);
switch (iOrigin) {
case SEEK_SET:
--
1.7.7.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment