[PATCH 3/5] s3-safe_str: Futher simplify the macros by removing indirection

Andrew Bartlett abartlet at samba.org
Tue Mar 22 03:57:36 MDT 2011


Now that we don't need to pass in the function name and string,
another level of indirection can be safely removed, and the operation
of these macros made much clearer.

Andrew Bartlett
---
 source3/include/proto.h       |   18 ++++++------
 source3/include/safe_string.h |   58 ++++++++++-------------------------------
 source3/lib/util_str.c        |   10 +++---
 source3/libsmb/clistr.c       |   26 +++++++++---------
 4 files changed, 41 insertions(+), 71 deletions(-)

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 4e6af8e..afdc73a 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1356,11 +1356,11 @@ char *safe_strcpy_fn(char *dest,
 char *safe_strcat_fn(char *dest,
 		const char *src,
 		size_t maxlength);
-char *alpha_strcpy_fn(char *dest,
+char *alpha_strcpy(char *dest,
 		const char *src,
 		const char *other_safe_chars,
 		size_t maxlength);
-char *StrnCpy_fn(char *dest,const char *src,size_t n);
+char *StrnCpy(char *dest,const char *src,size_t n);
 bool in_list(const char *s, const char *list, bool casesensitive);
 void string_free(char **s);
 bool string_set(char **dest,const char *src);
@@ -2332,13 +2332,13 @@ size_t clistr_pull_fn(const char *inbuf,
 			int dest_len,
 			int src_len,
 			int flags);
-size_t clistr_pull_talloc_fn(TALLOC_CTX *ctx,
-				const char *base,
-				uint16_t flags2,
-				char **pp_dest,
-				const void *src,
-				int src_len,
-				int flags);
+size_t clistr_pull_talloc(TALLOC_CTX *ctx,
+			  const char *base,
+			  uint16_t flags2,
+			  char **pp_dest,
+			  const void *src,
+			  int src_len,
+			  int flags);
 size_t clistr_align_out(struct cli_state *cli, const void *p, int flags);
 
 /* The following definitions come from libsmb/clitrans.c  */
diff --git a/source3/include/safe_string.h b/source3/include/safe_string.h
index f54464e..a4648b5 100644
--- a/source3/include/safe_string.h
+++ b/source3/include/safe_string.h
@@ -105,84 +105,54 @@ size_t __unsafe_string_function_usage_here_char__(void);
 #define overmalloc_safe_strcpy(dest,src,maxlength) \
 	safe_strcpy_fn(dest,src,maxlength)
 
-#define safe_strcpy(dest,src,maxlength) \
-	safe_strcpy_fn2(dest,src,maxlength)
-
-#define safe_strcat(dest,src,maxlength) \
-	safe_strcat_fn2(dest,src,maxlength)
-
-#define push_string_check(dest, src, dest_len, flags) \
-	push_string_check_fn2(dest, src, dest_len, flags)
-
-#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
-	pull_string_talloc_fn2(ctx, base_ptr, smb_flags2, dest, src, src_len, flags)
-
-#define clistr_push(cli, dest, src, dest_len, flags) \
-	clistr_push_fn2(cli, dest, src, dest_len, flags)
-
-#define clistr_pull(inbuf, dest, src, dest_len, src_len, flags) \
-	clistr_pull_fn2(inbuf, dest, src, dest_len, src_len, flags)
-
-#define clistr_pull_talloc(ctx, base, flags2, pp_dest, src, src_len, flags) \
-	clistr_pull_talloc_fn(ctx, base, flags2, pp_dest, src, src_len, flags)
-
-#define srvstr_push(base_ptr, smb_flags2, dest, src, dest_len, flags) \
-	srvstr_push_fn2(base_ptr, smb_flags2, dest, src, dest_len, flags)
-
-#define alpha_strcpy(dest,src,other_safe_chars,maxlength) \
-	alpha_strcpy_fn(dest,src,other_safe_chars,maxlength)
-
-#define StrnCpy(dest,src,n) \
-	StrnCpy_fn(dest,src,n)
-
 #ifdef HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS
 
 /* if the compiler will optimize out function calls, then use this to tell if we are 
    have the correct types (this works only where sizeof() returns the size of the buffer, not
    the size of the pointer). */
 
-#define safe_strcpy_fn2(d, s, max_len) \
+#define safe_strcpy(d, s, max_len) \
     (CHECK_STRING_SIZE(d, max_len+1) \
     ? __unsafe_string_function_usage_here__() \
     : safe_strcpy_fn((d), (s), (max_len)))
 
-#define safe_strcat_fn2(d, s, max_len) \
+#define safe_strcat(d, s, max_len) \
     (CHECK_STRING_SIZE(d, max_len+1) \
     ? __unsafe_string_function_usage_here__() \
     : safe_strcat_fn((d), (s), (max_len)))
 
-#define push_string_check_fn2(dest, src, dest_len, flags) \
+#define push_string_check(dest, src, dest_len, flags) \
     (CHECK_STRING_SIZE(dest, dest_len) \
     ? __unsafe_string_function_usage_here_size_t__() \
     : push_string_check_fn(dest, src, dest_len, flags))
 
-#define pull_string_talloc_fn2(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
+#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
     pull_string_talloc_fn(ctx, base_ptr, smb_flags2, dest, src, src_len, flags)
 
-#define clistr_push_fn2(cli, dest, src, dest_len, flags) \
+#define clistr_push(cli, dest, src, dest_len, flags) \
     (CHECK_STRING_SIZE(dest, dest_len) \
     ? __unsafe_string_function_usage_here_size_t__() \
     : clistr_push_fn(cli, dest, src, dest_len, flags))
 
-#define clistr_pull_fn2(inbuf, dest, src, dest_len, srclen, flags) \
+#define clistr_pull(inbuf, dest, src, dest_len, srclen, flags) \
     (CHECK_STRING_SIZE(dest, dest_len) \
     ? __unsafe_string_function_usage_here_size_t__() \
     : clistr_pull_fn(inbuf, dest, src, dest_len, srclen, flags))
 
-#define srvstr_push_fn2(base_ptr, smb_flags2, dest, src, dest_len, flags) \
+#define srvstr_push(base_ptr, smb_flags2, dest, src, dest_len, flags) \
     (CHECK_STRING_SIZE(dest, dest_len) \
     ? __unsafe_string_function_usage_here_size_t__() \
     : srvstr_push_fn(base_ptr, smb_flags2, dest, src, dest_len, flags))
 
 #else
 
-#define safe_strcpy_fn2 safe_strcpy_fn
-#define safe_strcat_fn2 safe_strcat_fn
-#define push_string_check_fn2 push_string_check_fn
-#define pull_string_talloc_fn2 pull_string_talloc_fn
-#define clistr_push_fn2 clistr_push_fn
-#define clistr_pull_fn2 clistr_pull_fn
-#define srvstr_push_fn2 srvstr_push_fn
+#define safe_strcpy safe_strcpy_fn
+#define safe_strcat safe_strcat_fn
+#define push_string_check push_string_check_fn
+#define pull_string_talloc pull_string_talloc_fn
+#define clistr_push clistr_push_fn
+#define clistr_pull clistr_pull_fn
+#define srvstr_push srvstr_push_fn
 
 #endif
 
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index a1dfc70..f14d7de 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -573,10 +573,10 @@ char *safe_strcat_fn(char *dest,
  characters. Don't change it !
 **/
 
-char *alpha_strcpy_fn(char *dest,
-		      const char *src,
-		      const char *other_safe_chars,
-		      size_t maxlength)
+char *alpha_strcpy(char *dest,
+		   const char *src,
+		   const char *other_safe_chars,
+		   size_t maxlength)
 {
 	size_t len, i;
 
@@ -614,7 +614,7 @@ char *alpha_strcpy_fn(char *dest,
  Like strncpy but always null terminates. Make sure there is room!
  The variable n should always be one less than the available size.
 **/
-char *StrnCpy_fn(char *dest,const char *src,size_t n)
+char *StrnCpy(char *dest,const char *src,size_t n)
 {
 	char *d = dest;
 
diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c
index 8856e03..373cce5 100644
--- a/source3/libsmb/clistr.c
+++ b/source3/libsmb/clistr.c
@@ -58,21 +58,21 @@ size_t clistr_pull_fn(const char *inbuf,
 			      src_len, flags);
 }
 
-size_t clistr_pull_talloc_fn(TALLOC_CTX *ctx,
-				const char *base,
-				uint16_t flags2,
-				char **pp_dest,
-				const void *src,
-				int src_len,
-				int flags)
+size_t clistr_pull_talloc(TALLOC_CTX *ctx,
+			  const char *base,
+			  uint16_t flags2,
+			  char **pp_dest,
+			  const void *src,
+			  int src_len,
+			  int flags)
 {
 	return pull_string_talloc_fn(ctx,
-					base,
-					flags2,
-					pp_dest,
-					src,
-					src_len,
-					flags);
+				     base,
+				     flags2,
+				     pp_dest,
+				     src,
+				     src_len,
+				     flags);
 }
 
 size_t clistr_align_out(struct cli_state *cli, const void *p, int flags)
-- 
1.7.4


--=-CKea5WF8d91yCrI3Skri
Content-Disposition: attachment; filename="0002-s3-lib-Remove-the-clobber_region-code.patch"
Content-Type: text/x-patch; name="0002-s3-lib-Remove-the-clobber_region-code.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



More information about the samba-technical mailing list