Merge pull request #59 from pali/master Fix compile warnings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
diff --git a/dlfcn.c b/dlfcn.c
index ce06d93..f8af91f 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -30,7 +30,6 @@
#ifdef _MSC_VER
/* https://docs.microsoft.com/en-us/cpp/intrinsics/returnaddress */
-#include <intrin.h>
#pragma intrinsic(_ReturnAddress)
#else
/* https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html */
@@ -455,11 +454,7 @@ end:
save_err_str( name );
}
- // warning C4054: 'type cast' : from function pointer 'FARPROC' to data pointer 'void *'
-#ifdef _MSC_VER
-#pragma warning( suppress: 4054 )
-#endif
- return (void*) symbol;
+ return *(void **) (&symbol);
}
char *dlerror( void )
diff --git a/test.c b/test.c
index 0d07f12..aa0e0f1 100644
--- a/test.c
+++ b/test.c
@@ -86,6 +86,7 @@ int main()
char toolongfile[32767];
DWORD code;
char nonlibraryfile[MAX_PATH];
+ DWORD length;
HANDLE tempfile;
DWORD dummy;
UINT uMode;
@@ -99,14 +100,14 @@ int main()
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
#endif
- ret = GetTempPathA( sizeof( nonlibraryfile ) - sizeof( "temp.dll" ), nonlibraryfile );
- if( ret == 0 || ret > sizeof( nonlibraryfile ) - sizeof( "temp.dll" ) )
+ length = GetTempPathA( sizeof( nonlibraryfile ) - sizeof( "temp.dll" ), nonlibraryfile );
+ if( length == 0 || length > sizeof( nonlibraryfile ) - sizeof( "temp.dll" ) )
{
printf( "ERROR\tGetTempPath failed\n" );
RETURN_ERROR;
}
- memcpy( nonlibraryfile + ret, "temp.dll", sizeof( "temp.dll" ) );
+ memcpy( nonlibraryfile + length, "temp.dll", sizeof( "temp.dll" ) );
tempfile = CreateFileA( (LPCSTR) nonlibraryfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
if( tempfile == INVALID_HANDLE_VALUE )
@@ -240,7 +241,7 @@ int main()
else
printf( "SUCCESS\tGot global handle: %p\n", global );
- fwrite_local = dlsym(global, "fwrite");
+ *(void **) (&fwrite_local) = dlsym( global, "fwrite" );
if (!fwrite_local)
{
error = dlerror();
@@ -251,12 +252,14 @@ int main()
RETURN_ERROR;
}
else
- printf("SUCCESS\tGot symbol from global handle: %p\n", fwrite_local);
- char * hello_world = "Hello world from local fwrite!\n";
- fwrite_local(hello_world,sizeof(char),strlen(hello_world),stderr);
- fflush(stderr);
+ printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&fwrite_local) );
+ {
+ const char *hello_world = "Hello world from local fwrite!\n";
+ fwrite_local( hello_world, sizeof( char ), strlen( hello_world ), stderr );
+ fflush( stderr );
+ }
- fputs_default = dlsym(RTLD_DEFAULT, "fputs");
+ *(void **) (&fputs_default) = dlsym( RTLD_DEFAULT, "fputs" );
if (!fputs_default)
{
error = dlerror();
@@ -267,12 +270,14 @@ int main()
RETURN_ERROR;
}
else
- printf("SUCCESS\tGot symbol from default handle: %p\n", fputs_default);
- char * hello_world_fputs = "Hello world from default fputs!\n";
- fputs_default(hello_world_fputs, stderr);
- fflush(stderr);
+ printf( "SUCCESS\tGot symbol from default handle: %p\n", *(void **) (&fputs_default) );
+ {
+ const char *hello_world_fputs = "Hello world from default fputs!\n";
+ fputs_default( hello_world_fputs, stderr );
+ fflush( stderr );
+ }
- function = dlsym( library, "function" );
+ *(void **) (&function) = dlsym( library, "function" );
if( !function )
{
error = dlerror( );
@@ -283,11 +288,11 @@ int main()
RETURN_ERROR;
}
else
- printf( "SUCCESS\tGot symbol from library handle: %p\n", function );
+ printf( "SUCCESS\tGot symbol from library handle: %p\n", *(void **) (&function) );
RUNFUNC;
- function2_from_library2 = dlsym( library2, "function2" );
+ *(void **) (&function2_from_library2) = dlsym( library2, "function2" );
if( !function2_from_library2 )
{
error = dlerror( );
@@ -298,7 +303,7 @@ int main()
RETURN_ERROR;
}
else
- printf( "SUCCESS\tGot symbol from library2 handle: %p\n", function2_from_library2 );
+ printf( "SUCCESS\tGot symbol from library2 handle: %p\n", *(void **) (&function2_from_library2) );
ret = function2_from_library2 ();
if( ret != 2 )
@@ -308,11 +313,11 @@ int main()
RETURN_ERROR;
}
- nonexistentfunction = dlsym( library, "nonexistentfunction" );
+ *(void **) (&nonexistentfunction) = dlsym( library, "nonexistentfunction" );
if( nonexistentfunction )
{
error = dlerror( );
- printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", nonexistentfunction );
+ printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", *(void **) (&nonexistentfunction) );
CLOSE_LIB;
CLOSE_GLOBAL;
RETURN_ERROR;
@@ -326,7 +331,7 @@ int main()
else
printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error );
- function = dlsym( global, "function" );
+ *(void **) (&function) = dlsym( global, "function" );
if( !function )
{
error = dlerror( );
@@ -337,15 +342,15 @@ int main()
RETURN_ERROR;
}
else
- printf( "SUCCESS\tGot symbol from global handle: %p\n", function );
+ printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) );
RUNFUNC;
- nonexistentfunction = dlsym( global, "nonexistentfunction" );
+ *(void **) (&nonexistentfunction) = dlsym( global, "nonexistentfunction" );
if( nonexistentfunction )
{
error = dlerror( );
- printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", nonexistentfunction );
+ printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", *(void **) (&nonexistentfunction) );
CLOSE_LIB;
CLOSE_GLOBAL;
RETURN_ERROR;
@@ -391,7 +396,7 @@ int main()
else
printf( "SUCCESS\tOpened library locally: %p\n", library );
- function = dlsym( library, "function" );
+ *(void **) (&function) = dlsym( library, "function" );
if( !function )
{
error = dlerror( );
@@ -402,15 +407,15 @@ int main()
RETURN_ERROR;
}
else
- printf( "SUCCESS\tGot symbol from library handle: %p\n", function );
+ printf( "SUCCESS\tGot symbol from library handle: %p\n", *(void **) (&function) );
RUNFUNC;
- nonexistentfunction = dlsym( library, "nonexistentfunction" );
+ *(void **) (&nonexistentfunction) = dlsym( library, "nonexistentfunction" );
if( nonexistentfunction )
{
error = dlerror( );
- printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", nonexistentfunction );
+ printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", *(void **) (&nonexistentfunction) );
CLOSE_LIB;
CLOSE_GLOBAL;
RETURN_ERROR;
@@ -424,12 +429,12 @@ int main()
else
printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error );
- function = dlsym( global, "function" );
+ *(void **) (&function) = dlsym( global, "function" );
if( function )
{
error = dlerror( );
printf( "ERROR\tGot local symbol from global handle: %s @ %p\n",
- error ? error : "", function );
+ error ? error : "", *(void **) (&function) );
CLOSE_LIB;
CLOSE_GLOBAL;
RETURN_ERROR;
@@ -437,11 +442,11 @@ int main()
else
printf( "SUCCESS\tDid not get local symbol from global handle.\n" );
- nonexistentfunction = dlsym( global, "nonexistentfunction" );
+ *(void **) (&nonexistentfunction) = dlsym( global, "nonexistentfunction" );
if( nonexistentfunction )
{
error = dlerror( );
- printf( "ERROR\tGot nonexistent local symbol from global handle: %p\n", nonexistentfunction );
+ printf( "ERROR\tGot nonexistent local symbol from global handle: %p\n", *(void **) (&nonexistentfunction) );
CLOSE_LIB;
CLOSE_GLOBAL;
RETURN_ERROR;
@@ -467,7 +472,7 @@ int main()
else
printf( "SUCCESS\tOpened library globally without closing it first: %p\n", library );
- function = dlsym( global, "function" );
+ *(void **) (&function) = dlsym( global, "function" );
if( !function )
{
error = dlerror( );
@@ -478,15 +483,15 @@ int main()
RETURN_ERROR;
}
else
- printf( "SUCCESS\tGot symbol from global handle: %p\n", function );
+ printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) );
RUNFUNC;
- nonexistentfunction = dlsym( global, "nonexistentfunction" );
+ *(void **) (&nonexistentfunction) = dlsym( global, "nonexistentfunction" );
if( nonexistentfunction )
{
error = dlerror( );
- printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", nonexistentfunction );
+ printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", *(void **) (&nonexistentfunction) );
CLOSE_LIB;
CLOSE_GLOBAL;
RETURN_ERROR;
@@ -517,7 +522,7 @@ int main()
}
}
- function = dlsym(global, "fwrite");
+ *(void **) (&function) = dlsym( global, "fwrite" );
if (!function)
{
error = dlerror();
@@ -528,7 +533,7 @@ int main()
RETURN_ERROR;
}
else
- printf("SUCCESS\tGot symbol from global handle: %p\n", function);
+ printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) );
uMode = SetErrorMode( SEM_FAILCRITICALERRORS );
@@ -540,7 +545,7 @@ int main()
RETURN_ERROR;
}
else
- printf( "SUCCESS\tOpened library3 via WINAPI: %p\n", library3 );
+ printf( "SUCCESS\tOpened library3 via WINAPI: %p\n", (void *)library3 );
ret = dlclose( library );
if( ret )
@@ -553,7 +558,7 @@ int main()
else
printf( "SUCCESS\tClosed library.\n" );
- function = dlsym(global, "function3");
+ *(void **) (&function) = dlsym( global, "function3" );
if (!function)
{
error = dlerror();
@@ -564,7 +569,7 @@ int main()
RETURN_ERROR;
}
else
- printf("SUCCESS\tGot symbol from global handle: %p\n", function);
+ printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) );
RUNFUNC;
diff --git a/testdll2.c b/testdll2.c
index 910c820..71d385a 100644
--- a/testdll2.c
+++ b/testdll2.c
@@ -38,7 +38,7 @@ EXPORT int function2( void )
char *error;
int (*function2_orig)(void);
printf( "Hello, world! from wrapper library\n" );
- function2_orig = dlsym(RTLD_NEXT, "function2");
+ *(void **) (&function2_orig) = dlsym( RTLD_NEXT, "function2" );
if (!function2_orig)
{
error = dlerror( );