Skip to content
Snippets Groups Projects
Commit 966cd458 authored by rswindell's avatar rswindell
Browse files

Remove the src==dst comparison in SAFECOPY() - we want Valgrind to find

occurances of these calls and report them (they're bugs).
Use the TERMINATE function in the strncpy version of SAFECOPY()
(does it need the int-typecast Deuce?).
parent 5498da5f
Branches
Tags
No related merge requests found
...@@ -233,13 +233,17 @@ typedef struct { ...@@ -233,13 +233,17 @@ typedef struct {
/* Handy String Macros */ /* Handy String Macros */
/***********************/ /***********************/
/* Null-Terminate an ASCIIZ char array */
#define TERMINATE(str) str[sizeof(str)-1]=0
/* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */ /* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
#ifdef SAFECOPY_USES_SPRINTF #ifdef SAFECOPY_USES_SPRINTF
#define SAFECOPY(dst,src) sprintf(dst,"%.*s",(int)sizeof(dst)-1,src) #define SAFECOPY(dst,src) sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
#else #else /* strncpy is faster */
#define SAFECOPY(dst,src) ((((char *)(dst))==((char *)(src)))?0:(strncpy(dst,src,sizeof(dst)), dst[(int)sizeof(dst)-1]=0)) #define SAFECOPY(dst,src) (strncpy(dst,src,sizeof(dst)), TERMINATE(dst))
#endif #endif
#define TERMINATE(str) str[sizeof(str)-1]=0
/* Bound-safe version of sprintf() - only works with fixed-length arrays */
#if (defined __FreeBSD__) || (defined __NetBSD__) || (defined __OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__)) #if (defined __FreeBSD__) || (defined __NetBSD__) || (defined __OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__))
/* *BSD *nprintf() is already safe */ /* *BSD *nprintf() is already safe */
#define SAFEPRINTF(dst,fmt,arg) snprintf(dst,sizeof(dst),fmt,arg) #define SAFEPRINTF(dst,fmt,arg) snprintf(dst,sizeof(dst),fmt,arg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment