s3-safe_str: Futher simplify the macros by removing indirection
authorAndrew Bartlett <abartlet@samba.org>
Tue, 22 Mar 2011 09:57:36 +0000 (20:57 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 23 Mar 2011 01:49:39 +0000 (12:49 +1100)
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
source3/include/safe_string.h
source3/lib/util_str.c
source3/libsmb/clistr.c

index d806b36dd20e8d6c74e68098a75a73b21bdd2d65..0f313d637e2cf8dae731ce17cc83f6fbe5d5a4a6 100644 (file)
@@ -1352,11 +1352,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);
@@ -2328,13 +2328,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  */
index f54464e9c04e608ca3f8cbe15bacc94bef58ff58..a4648b57d44e8a44bf090aa89b4df6f4afe7d1b3 100644 (file)
@@ -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
 
index a1dfc707075d848ba458fba307275315b67a32a5..f14d7dea925ebf1cbc9ac5b15a7fbc44f9a5115e 100644 (file)
@@ -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;
 
index 8856e03dd0438c18f9deac2f90a4f969de35229b..373cce590dda9dc23014e1b2733a3458925c3e96 100644 (file)
@@ -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)