[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem building 0.8.0 with VS 2015


On Monday, 13 August 2018 23:22:07 CEST John Dunn wrote:
> On Monday, August 13, 2018 12:18 PM Andreas Schneider wrote:
> > This should fix it:
> >https://git.libssh.org/users/asn/libssh.git/log/?h=master-fix
> 
> I get the following error when loading the DLL. My guess is that the
> DLL_THREAD_ATTACH event is causing this issue. Initializing rc to 0 fixes
> the issue.
> 
> ---------------------------
> Microsoft Visual C++ Runtime Library
> ---------------------------
> Debug Error!
> 
> Program: ..xxx\Debug\sshd.dll
> Module: ...xxx\Debug\sshd.dll
> File: c:\code\foo\libssh\src\init.c
> Line: 239
> 
> Run-Time Check Failure #3 - The variable 'rc' is being used without being
> initialized.
> 
> (Press Retry to debug the application)
> 
> ---------------------------
> Abort   Retry   Ignore
> ---------------------------

It took me a while to find the documentation I hope this is correct now. 
Please use try the attached patch on top of 0.8.1.

Thanks!
From 198ac1359bbab296c8f3f52c31975cfa7969da64 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@xxxxxxxxxxxxxx>
Date: Tue, 14 Aug 2018 08:13:37 +0200
Subject: [PATCH] init: Fix DllMain

Signed-off-by: Andreas Schneider <asn@xxxxxxxxxxxxxx>
---
 src/init.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/init.c b/src/init.c
index ea3e6432..dc8d8cef 100644
--- a/src/init.c
+++ b/src/init.c
@@ -226,19 +226,27 @@ int ssh_finalize(void) {
 
 #ifdef _MSC_VER
 /* Library constructor and destructor */
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+BOOL WINAPI DllMain(HINSTANCE hinstDLL,
+                    DWORD fdwReason,
+                    LPVOID lpvReserved)
 {
-    int rc;
+    int rc = 0;
 
-    if (fdwReason == DLL_PROCESS_ATTACH) {
-        rc = ssh_init();
-    } else if (fdwReason == DLL_PROCESS_DETACH) {
-        rc = ssh_finalize();
+    switch(fdwReason) {
+    case DLL_PROCESS_ATTACH:
+        rc = _ssh_init(1);
+        if (rc != 0) {
+            fprintf(stderr, "DllMain: ssh_init failed!");
+            return FALSE;
+        }
+        break;
+    case DLL_PROCESS_DETACH:
+        _ssh_finalize(1);
+        break;
+    default:
+        break;
     }
 
-    if (rc != 0) {
-        return FALSE;
-    }
     return TRUE;
 }
 #endif /* _MSC_VER */
-- 
2.17.1


References:
Problem building 0.8.0 with VS 2015John Dunn <John.Dunn@xxxxxxx>
Re: Problem building 0.8.0 with VS 2015Andreas Schneider <asn@xxxxxxxxxxxxxx>
RE: Problem building 0.8.0 with VS 2015John Dunn <John.Dunn@xxxxxxx>
Archive administrator: postmaster@lists.cynapses.org