diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-05-10 13:49:32 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-05-10 13:51:25 +0200 |
commit | 1a1a7a8a27b15e31a408b8cb787e4045eaa57f87 (patch) | |
tree | 4aecda17254a6c6aade6a2f90fd1ae700d391765 /lib/gstr.h | |
parent | 0e6e66769c09e9653e7bbc41e40f4c6a6720305b (diff) | |
download | libtasn1-1a1a7a8a27b15e31a408b8cb787e4045eaa57f87.tar.gz libtasn1-1a1a7a8a27b15e31a408b8cb787e4045eaa57f87.tar.bz2 libtasn1-1a1a7a8a27b15e31a408b8cb787e4045eaa57f87.zip |
prevent memset() from being optimized out.
Diffstat (limited to 'lib/gstr.h')
-rw-r--r-- | lib/gstr.h | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -25,3 +25,18 @@ void _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src); #define Estrcpy(x,y) _asn1_str_cpy(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) #define Estrcat(x,y) _asn1_str_cat(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) + +inline static +void safe_memset(void *data, int c, size_t size) +{ + volatile unsigned volatile_zero = 0; + volatile char *vdata = (volatile char*)data; + + /* This is based on a nice trick for safe memset, + * sent by David Jacobson in the openssl-dev mailing list. + */ + + do { + memset(data, c, size); + } while(vdata[volatile_zero] != c); +} |