From 623c0d6f948849f2874e3358565646554bb78176 Mon Sep 17 00:00:00 2001
From: Marcus Meissner <marcus@jet.franken.de>
Date: Sat, 3 Jul 1999 16:01:42 +0000
Subject: [PATCH] some small include fixes, some checks for NULL ptrs,
 loader/elf.c: fixed the "lib" insertion crtdll: added fsopen() dinput: return
 that we are attached.

---
 dlls/advapi32/advapi.c    | 2 +-
 dlls/advapi32/eventlog.c  | 1 +
 dlls/avifil32/avifile.c   | 2 +-
 dlls/comctl32/propsheet.c | 1 +
 dlls/comctl32/trackbar.c  | 1 +
 dlls/version/resource.c   | 3 ---
 if1632/relay.c            | 1 +
 include/win.h             | 1 +
 loader/elf.c              | 6 ++++--
 loader/pe_image.c         | 8 +-------
 misc/crtdll.c             | 4 ++++
 misc/shell.c              | 1 +
 multimedia/dsound.c       | 2 +-
 relay32/crtdll.spec       | 2 +-
 windows/dinput.c          | 1 +
 15 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/dlls/advapi32/advapi.c b/dlls/advapi32/advapi.c
index 0a934bca73a..646f0f86250 100644
--- a/dlls/advapi32/advapi.c
+++ b/dlls/advapi32/advapi.c
@@ -8,10 +8,10 @@
 #include <unistd.h>
 #include <string.h>
 
+#include "winbase.h"
 #include "windef.h"
 #include "winerror.h"
 #include "wine/winestring.h"
-#include "heap.h"
 
 #include "debugtools.h"
 
diff --git a/dlls/advapi32/eventlog.c b/dlls/advapi32/eventlog.c
index f0b21519ebb..cc74f29fa54 100644
--- a/dlls/advapi32/eventlog.c
+++ b/dlls/advapi32/eventlog.c
@@ -4,6 +4,7 @@
  * Copyright 1995 Sven Verdoolaege, 1998 Juergen Schmied
  */
 
+#include "winbase.h"
 #include "windef.h"
 #include "winreg.h"
 #include "winerror.h"
diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c
index 3dbc987e566..63a792ef845 100644
--- a/dlls/avifil32/avifile.c
+++ b/dlls/avifil32/avifile.c
@@ -5,8 +5,8 @@
 #include <stdio.h>
 #include <assert.h>
 
-#include "vfw.h"
 #include "winbase.h"
+#include "vfw.h"
 #include "wine/winestring.h"
 #include "driver.h"
 #include "mmsystem.h"
diff --git a/dlls/comctl32/propsheet.c b/dlls/comctl32/propsheet.c
index ceb20d9db39..f7ad3c50c2e 100644
--- a/dlls/comctl32/propsheet.c
+++ b/dlls/comctl32/propsheet.c
@@ -761,6 +761,7 @@ static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
   PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                     PropSheetInfoStr);
 
+  if (!psInfo) return;
   /*
    * Set the dirty flag of this page.
    */
diff --git a/dlls/comctl32/trackbar.c b/dlls/comctl32/trackbar.c
index 9e981651090..0b7215b5579 100644
--- a/dlls/comctl32/trackbar.c
+++ b/dlls/comctl32/trackbar.c
@@ -167,6 +167,7 @@ TRACKBAR_CalcThumb (HWND hwnd, TRACKBAR_INFO *infoPtr)
 	
     thumb=&infoPtr->rcThumb;
     range=infoPtr->nRangeMax - infoPtr->nRangeMin;
+    if (!range) return; /* FIXME: may this happen? */
     if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_VERT) {
     	width=infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
         thumb->left  = infoPtr->rcChannel.left - 1;
diff --git a/dlls/version/resource.c b/dlls/version/resource.c
index d3c68a03e1a..9701ea88ed4 100644
--- a/dlls/version/resource.c
+++ b/dlls/version/resource.c
@@ -9,13 +9,10 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "peexe.h"
 #include "neexe.h"
 #include "module.h"
 #include "winver.h"
-#include "heap.h"
 #include "lzexpand.h"
-#include "peexe.h"
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(ver)
diff --git a/if1632/relay.c b/if1632/relay.c
index 94f079b18dd..ec8d32bc9fb 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -13,6 +13,7 @@
 #include "module.h"
 #include "stackframe.h"
 #include "task.h"
+#include "syslevel.h"
 #include "debugstr.h"
 #include "debugtools.h"
 #include "main.h"
diff --git a/include/win.h b/include/win.h
index a3b0a00b70a..4b0c708218d 100644
--- a/include/win.h
+++ b/include/win.h
@@ -7,6 +7,7 @@
 #ifndef __WINE_WIN_H
 #define __WINE_WIN_H
 
+#include "winuser.h"
 #include "queue.h"
 #include "class.h"
 
diff --git a/loader/elf.c b/loader/elf.c
index d4ba4e93436..d4f9af6aebf 100644
--- a/loader/elf.c
+++ b/loader/elf.c
@@ -114,8 +114,10 @@ WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags, DWORD *err)
 	if (!s)
 		s=strrchr(libname,'\\');
 	if (s) {
-		strncpy(t,libname,s-libname+1);
-		t[s-libname+1]= '\0';
+		s++; /* skip / or \ */
+		/* copy everything up to s-1 */
+		memcpy(t,libname,s-libname);
+		t[s-libname]= '\0';
 	} else
 		s = (LPSTR)libname;
 	modname = s;
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 36d16b41186..8892f158e8f 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -422,14 +422,8 @@ static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r )
 				*(short*)(page+offset) += ldelta;
 				break;
 			case IMAGE_REL_BASED_HIGHLOW:
-#if 1
 				*(int*)(page+offset) += delta;
-#else
-				{ int h=*(unsigned short*)(page+offset);
-				  int l=r->TypeOffset[++i];
-				  *(unsigned int*)(page + offset) = (h<<16) + l + delta;
-				}
-#endif
+				/* FIXME: if this is an exported address, fire up enhanced logic */
 				break;
 			case IMAGE_REL_BASED_HIGHADJ:
 				FIXME_(win32)("Don't know what to do with IMAGE_REL_BASED_HIGHADJ\n");
diff --git a/misc/crtdll.c b/misc/crtdll.c
index 98d93f41436..e1ced3e1341 100644
--- a/misc/crtdll.c
+++ b/misc/crtdll.c
@@ -247,6 +247,10 @@ DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
 	return 0;
 }
 
+CRTDLL_FILE * __cdecl CRTDLL__fsopen(LPCSTR x, LPCSTR y, INT z) {
+	FIXME("(%s,%s,%d),stub!\n",x,y,z);
+	return NULL;
+}
 /*********************************************************************
  *                  _fdopen     (CRTDLL.91)
  */
diff --git a/misc/shell.c b/misc/shell.c
index e22f21bd41f..6a1765550f4 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -23,6 +23,7 @@
 #include "shlobj.h"
 #include "debugtools.h"
 #include "winreg.h"
+#include "syslevel.h"
 #include "imagelist.h"
 
 DECLARE_DEBUG_CHANNEL(exec)
diff --git a/multimedia/dsound.c b/multimedia/dsound.c
index 9165664a659..2cd37c5e492 100644
--- a/multimedia/dsound.c
+++ b/multimedia/dsound.c
@@ -2277,7 +2277,7 @@ HRESULT WINAPI DirectSoundCreate(REFGUID lpGUID,LPDIRECTSOUND *ppDS,IUnknown *pU
 		} else if (errno == EBUSY) {
 			MSG("Sound device busy, will keep trying.\n");
 		} else {
-			MSG("Unexpected error while checking for sound support.\n");
+			MSG("Unexpected error (%d) while checking for sound support.\n",errno);
 			return DSERR_GENERIC;
 		}
 	} else {
diff --git a/relay32/crtdll.spec b/relay32/crtdll.spec
index 94ce21dc8f7..e851f43057d 100644
--- a/relay32/crtdll.spec
+++ b/relay32/crtdll.spec
@@ -112,7 +112,7 @@ init    CRTDLL_Init
 107 cdecl _fpreset() CRTDLL__fpreset
 108 stub _fputchar
 109 stub _fputwchar
-110 stub _fsopen
+110 cdecl _fsopen(str str long) CRTDLL__fsopen
 111 cdecl _fstat(long ptr) CRTDLL__fstat
 112 stub _ftime
 113 cdecl _ftol() CRTDLL__ftol
diff --git a/windows/dinput.c b/windows/dinput.c
index 35e2d3f8408..b77d203f5b4 100644
--- a/windows/dinput.c
+++ b/windows/dinput.c
@@ -517,6 +517,7 @@ static HRESULT WINAPI IDirectInputDevice2AImpl_GetCapabilities(
 	LPDIRECTINPUTDEVICE2A iface,
 	LPDIDEVCAPS lpDIDevCaps)
 {
+	lpDIDevCaps->dwFlags = DIDC_ATTACHED;
 	FIXME(dinput, "stub!\n");
 	return DI_OK;
 }
-- 
GitLab