From: unknown Date: Thu, 28 Jul 2011 09:22:25 +0000 (+0200) Subject: Prefer check size of void* against write 4 or 8 X-Git-Tag: v3_6_2~188^2~1^2~11 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ae75dd12f2b82912c1470c744d258a67ffae54dc?ds=sidebyside Prefer check size of void* against write 4 or 8 --- diff --git a/src/xbt/win32_ucontext.c b/src/xbt/win32_ucontext.c index 757eb43a70..c91c39e426 100644 --- a/src/xbt/win32_ucontext.c +++ b/src/xbt/win32_ucontext.c @@ -21,6 +21,7 @@ */ #include "win32_ucontext.h" + int getcontext(ucontext_t * ucp) { int ret; @@ -45,12 +46,12 @@ int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) int i; va_list ap; char *sp; - - /* Stack grows down */ + + /* Stack grows down */ sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size; /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ - sp -= argc * 8; + sp -= argc * sizeof(void*); if (sp < (char *) ucp->uc_stack.ss_sp) { /* errno = ENOMEM; */ @@ -59,15 +60,15 @@ int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) /* Set the instruction and the stack pointer */ #ifdef I_X86_ - ucp->uc_mcontext.Eip = (unsigned long) func; - ucp->uc_mcontext.Esp = (unsigned long) sp - 4; + ucp->uc_mcontext.Eip = (DWORD) func; + ucp->uc_mcontext.Esp = (DWORD) sp - sizeof(void*); #endif #ifdef _IA64_ # error "_IA64_" #endif #ifdef _AMD64_ - ucp->uc_mcontext.Rip = (unsigned long long) func; - ucp->uc_mcontext.Rsp = (unsigned long long) sp - 8; + ucp->uc_mcontext.Rip = (DWORD64) func; + ucp->uc_mcontext.Rsp = (DWORD64) sp - sizeof(void*); #endif /* Save/Restore the full machine context */ @@ -76,9 +77,9 @@ int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) /* Copy the arguments */ va_start(ap, argc); for (i = 0; i < argc; i++) { - memcpy(sp, ap, 8); - ap += 8; - sp += 8; + memcpy(sp, ap, sizeof(void*)); + ap += sizeof(void*); + sp += sizeof(void*); } va_end(ap); return 0;