Linda
Linda

Reputation: 1971

Warning on compiling Xcode with file md5.c

I am using the md5.c file in an iOS app. http://opensource.apple.com/source/cvs/cvs-33/cvs/lib/md5.c?txt

When I compile, I get the error: Argument to 'sizeof' in 'builtin_memset_chk' call is the same expression as the destination; did you mean to dereference it?

This is in the line that is: memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */

What needs to be changed?

Linda

Upvotes: 0

Views: 383

Answers (2)

David Hoerl
David Hoerl

Reputation: 41652

You can get rid of the warning by:

size_t len = sizeof(ctx);
memset(ctx, 0, len);

But that would simply nil the first 4 bytes of the structure. As @dans3itz said, its probably a code error and sizeof(*ctx) is probably what is meant. Since as the comment says this is for "protection", it was not really necessary for the operation of the function. Interesting that no one picked this up in all the years this code has been out.

Upvotes: 0

dans3itz
dans3itz

Reputation: 1615

I think the compiler is asking if you want to change that line of code to:

memset(ctx, 0, sizeof(*ctx));

Upvotes: 3

Related Questions