Cleanup, dead code removal, some pretty insignificant security stuff that's based on recommendations.

This commit is contained in:
Adam Ierymenko 2014-04-18 00:14:12 -07:00
parent 5f45977e3e
commit 7831c4bfef
6 changed files with 31 additions and 33 deletions

View file

@ -85,6 +85,20 @@ public:
return (diff == 0ULL);
}
/**
* Securely zero memory
*
* This just uses volatile to ensure that it's never optimized out.
*/
static inline void burn(void *ptr,unsigned int len)
throw()
{
volatile unsigned char *p = (unsigned char *)ptr;
volatile unsigned char *e = p + len;
while (p != e)
*(p++) = (unsigned char)0;
}
/**
* Delete a file
*
@ -432,21 +446,12 @@ public:
*/
static std::string trim(const std::string &s);
/**
* Like sprintf, but appends to std::string
*
* @param s String to append to
* @param fmt Printf format string
* @param ... Format arguments
* @throws std::bad_alloc Memory allocation failure
* @throws std::length_error Format + args exceeds internal buffer maximum
*/
static void stdsprintf(std::string &s,const char *fmt,...)
throw(std::bad_alloc,std::length_error);
/**
* Variant of snprintf that is portable and throws an exception
*
* This just wraps the local implementation whatever it's called, while
* performing a few other checks and adding exceptions for overflow.
*
* @param buf Buffer to write to
* @param len Length of buffer in bytes
* @param fmt Format string