use of memset and optimization

Jeffrey Altman jaltman at columbia.edu
Fri Nov 8 08:50:00 EST 2002


Just wondering.  What are the declarations for memset() in the header
files that come with those compilers?


> --=-=-=
> 
> By examining the assembly output for the following test C file, I
> conclude that gcc 3.0.3 on sparc/solaris8, when given the "-O" flag,
> inlines the call to strncpy() for g() and h() and removes the call to
> memset().  For f(), it doesn't remove the call to memset.  Using
> either gcc 2.95.3 or sun's C compiler, with any non-zero level of
> optimization, does not appear to optimize out the call to memset(),
> though gcc 2.95.3 does seem to inline the memset() calls.
> 
> Both gcc 3.0.3 and gcc 2.95.3 inline but do not eliminate the memset()
> call in h2(), which is valid behavior -- the "static" storage duration
> qualifier means that some other function, e.g. encrypt(), may retain a
> pointer to that object after h2() returns.
> 
> ---Tom
> 
> 
> --=-=-=
> Content-Disposition: inline; filename=opttest.c
> 
> #include <string.h>
> 
> extern void encrypt(char *, int, char *);
> 
> void f(char *buf, int len, char *key)
> {
>     encrypt(buf, len, key);
>     memset(key, 0, 16);
> }
> 
> void g(char *buf, int len)
> {
>     char key[16];
> 
>     strncpy(key, "seekrit89012345", sizeof(key));
>     encrypt(buf, len, key);
>     memset(key, 0, sizeof(key));
> }
> 
> void h(char *buf, int len)
> {
>     char key[64];
> 
>     strncpy(key, "seekrit89012345", sizeof(key));
>     encrypt(buf, len, key);
>     memset(key, 0, sizeof(key));
> }
> 
> void h2(char *buf, int len)
> {
>     static char key[64];
> 
>     strncpy(key, "seekrit89012345", sizeof(key));
>     encrypt(buf, len, key);
>     memset(key, 0, sizeof(key));
> }
> 
> --=-=-=--
> _______________________________________________
> krbdev mailing list             krbdev at mit.edu
> http://mailman.mit.edu/mailman/listinfo/krbdev
> 


 Jeffrey Altman * Sr.Software Designer     Kermit 95 2.0 GUI available now!!!
 The Kermit Project @ Columbia University  SSH, Secure Telnet, Secure FTP, HTTP
 http://www.kermit-project.org/            Secured with MIT Kerberos, SRP, and 
 kermit-support at columbia.edu               OpenSSL.



More information about the krbdev mailing list