Skip to content
Snippets Groups Projects
Commit b4a22d94 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add XSAFECOPY (extra safe copy) that won't pass NULL to strncpy()

The previous (reverted) change to SAFECOPY would double-resolve the (src)
argument and caused weird side effects.

Again, removes SAFECOPY_USES_SNPRINTF since it was unused.
parent bb163f65
No related branches found
No related tags found
No related merge requests found
......@@ -430,11 +430,9 @@ typedef struct {
#define TERMINATE(str) str[sizeof(str)-1]=0
/* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
#ifdef SAFECOPY_USES_SPRINTF
#define SAFECOPY(dst,src) sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
#else /* strncpy is faster */
#define SAFECOPY(dst,src) (strncpy(dst,src,sizeof(dst)), TERMINATE(dst))
#endif
/* Extra-safe SAFECOPY doesn't pass NULL-pointer to strncpy */
#define XSAFECOPY(dst,src) (strncpy(dst,(src)==NULL?"(null)":(src),sizeof(dst)), TERMINATE(dst))
#define SAFECAT(dst, src) do { \
if(strlen((char*)(dst)) + strlen((char*)(src)) < sizeof(dst)) { \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment