Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Type-casting pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 15 Topic 25019 of 28006
Post > Topic >>

Type-casting problems

by Ramon <ramif_47@[EMAIL PROTECTED] > Mar 20, 2008 at 09:29 AM

I have a pointer (result) of type void, which is passed (via parameter) 
to another function named preocessResult().

At processResult() a pointer of type int (res) is malloced and data is 
stored in the allocated space.  res is type-casted to void * and 
returned as result.


Everything seems to be ok, but when I run valgrind it gives the 
following warnings:

==3186== Invalid read of size 1
==3186==    at 0x401EB8C: memcpy (mc_replace_strmem.c:406)
==3186==    by 0x804844A: foo (test.c:43)
==3186==    by 0x8048462: main (test.c:54)
==3186==  Address 0x416408B is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186==    at 0x401EB91: memcpy (mc_replace_strmem.c:406)
==3186==    by 0x804844A: foo (test.c:43)
==3186==    by 0x8048462: main (test.c:54)
==3186==  Address 0x416408A is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186==    at 0x401EB98: memcpy (mc_replace_strmem.c:406)
==3186==    by 0x804844A: foo (test.c:43)
==3186==    by 0x8048462: main (test.c:54)
==3186==  Address 0x4164089 is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186==    at 0x401EB9F: memcpy (mc_replace_strmem.c:406)
==3186==    by 0x804844A: foo (test.c:43)
==3186==    by 0x8048462: main (test.c:54)
==3186==  Address 0x4164088 is not stack'd, malloc'd or (recently) free'd


Can any one figures out where is the mistake(s) please?
Here is my code:



void processResult(void **result)
{
     int *res = (int *) malloc(sizeof(int));

     *res = 505;
     *result = res;
}



void foo()
{
     void          *result = NULL;
     struct mytask mtask;


     processResult(&result);

     if (result == NULL)
         bzero( &mtask, sizeof(struct mytask) );
     else
         mtask   = *((struct mytask *) result);
}
 




 15 Posts in Topic:
Type-casting problems
Ramon <ramif_47@[EMAIL  2008-03-20 09:29:20 
Re: Type-casting problems
santosh <santosh.k83@[  2008-03-20 14:39:45 
Re: Type-casting problems
Ramon <ramif_47@[EMAIL  2008-03-20 10:52:42 
Re: Type-casting problems
richard@[EMAIL PROTECTED]  2008-03-20 10:46:17 
Re: Type-casting problems
Ramon <ramif_47@[EMAIL  2008-03-20 12:03:24 
Re: Type-casting problems
richard@[EMAIL PROTECTED]  2008-03-20 11:17:05 
Re: Type-casting problems
Ramon <ramif_47@[EMAIL  2008-03-20 12:57:43 
Re: Type-casting problems
richard@[EMAIL PROTECTED]  2008-03-20 12:02:03 
Re: Type-casting problems
Ramon <ramif_47@[EMAIL  2008-03-20 13:37:33 
Re: Type-casting problems
CBFalconer <cbfalconer  2008-03-20 20:11:17 
Re: Type-casting problems
"Rod Pemberton"  2008-03-20 14:36:38 
Re: Type-casting problems
Ben Bacarisse <ben.use  2008-03-20 10:54:40 
Re: Type-casting problems
richard@[EMAIL PROTECTED]  2008-03-20 11:19:20 
Re: Type-casting problems
Ben Bacarisse <ben.use  2008-03-20 13:23:07 
Re: Type-casting problems
Ben Bacarisse <ben.use  2008-03-20 13:40:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 12:14:49 CST 2008.