RE: segv at strcmp

From: Luck, Tony <tony.luck_at_intel.com>
Date: 2004-01-06 07:10:14
The <bits/string2.h> on my machine (came from the
glibc-devel-2.3.2-63 package in RedHat EL3). Looks
like it will only convert a strcmp to a memcmp if
*both* the arguments are constant:

# define strcmp(s1, s2) \
  __extension__                                                               \
  ({ size_t __s1_len, __s2_len;                                               \
     (__builtin_constant_p (s1) && __builtin_constant_p (s2)                  \
      && (__s1_len = strlen (s1), __s2_len = strlen (s2),                     \
          (!__string2_1bptr_p (s1) || __s1_len >= 4)                          \
          && (!__string2_1bptr_p (s2) || __s2_len >= 4))                      \
      ? memcmp ((__const char *) (s1), (__const char *) (s2),                 \
                (__s1_len < __s2_len ? __s1_len : __s2_len) + 1)              \
      : (__builtin_constant_p (s1) && __string2_1bptr_p (s1)                  \
         && (__s1_len = strlen (s1), __s1_len < 4)                            \
         ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2)               \
            ? __strcmp_cc (s1, s2, __s1_len)                                  \
            : __strcmp_cg (s1, s2, __s1_len))                                 \
         : (__builtin_constant_p (s2) && __string2_1bptr_p (s2)               \
            && (__s2_len = strlen (s2), __s2_len < 4)                         \
            ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1)            \
               ? __strcmp_cc (s1, s2, __s2_len)                               \
               : __strcmp_gc (s1, s2, __s2_len))                              \
            : strcmp (s1, s2)))); })

(I say "looks like" because I'm getting dizzy trying to match
parentheses in that expression).  Clearly your test case managed
to convert to memcmp when the first argument was not a constant
string ... which caused you grief.

-Tony
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Mon Jan 5 15:14:42 2004

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:21 EST