log: add \n
[oweals/gnunet.git] / src / regex / regex_internal.c
index 2dccd657fdb89f5772235416b8f92b3f897ae7ac..a74471ba12973edfd4b51dfc9c42f656c2e3cb8c 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     Copyright (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file src/regex/regex_internal.c
@@ -606,6 +606,8 @@ sb_nullstrcmp (const struct StringBuffer *s1,
     return -1;
   if (s1->slen != s2->slen)
     return -1;
+  if (0 == s1->slen)
+    return 0;
   return memcmp (s1->sbuf, s2->sbuf, s1->slen);
 }
 
@@ -624,6 +626,8 @@ sb_strcmp (const struct StringBuffer *s1,
 {
   if (s1->slen != s2->slen)
     return -1;
+  if (0 == s1->slen)
+    return 0;
   return memcmp (s1->sbuf, s2->sbuf, s1->slen);
 }
 
@@ -645,7 +649,7 @@ sb_realloc (struct StringBuffer *ret,
   old = ret->abuf;
   ret->abuf = GNUNET_malloc (nlen);
   ret->blen = nlen;
-  memcpy (ret->abuf,
+  GNUNET_memcpy (ret->abuf,
          ret->sbuf,
          ret->slen);
   ret->sbuf = ret->abuf;
@@ -668,7 +672,7 @@ sb_append (struct StringBuffer *ret,
   ret->null_flag = GNUNET_NO;
   if (ret->blen < sarg->slen + ret->slen)
     sb_realloc (ret, ret->blen + sarg->slen + 128);
-  memcpy (&ret->sbuf[ret->slen],
+  GNUNET_memcpy (&ret->sbuf[ret->slen],
          sarg->sbuf,
          sarg->slen);
   ret->slen += sarg->slen;
@@ -692,7 +696,7 @@ sb_append_cstr (struct StringBuffer *ret,
   ret->null_flag = GNUNET_NO;
   if (ret->blen < cstr_len + ret->slen)
     sb_realloc (ret, ret->blen + cstr_len + 128);
-  memcpy (&ret->sbuf[ret->slen],
+  GNUNET_memcpy (&ret->sbuf[ret->slen],
          cstr,
          cstr_len);
   ret->slen += cstr_len;
@@ -871,7 +875,7 @@ sb_strdup (struct StringBuffer *out,
   }
   out->sbuf = out->abuf;
   out->slen = in->slen;
-  memcpy (out->sbuf, in->sbuf, out->slen);
+  GNUNET_memcpy (out->sbuf, in->sbuf, out->slen);
 }
 
 
@@ -899,7 +903,7 @@ sb_strdup_cstr (struct StringBuffer *out,
                       out->slen);
   }
   out->sbuf = out->abuf;
-  memcpy (out->sbuf, cstr, out->slen);
+  GNUNET_memcpy (out->sbuf, cstr, out->slen);
 }
 
 
@@ -1067,7 +1071,7 @@ remove_epsilon (const struct StringBuffer *str,
     }
     ret->sbuf = ret->abuf;
     ret->slen = str->slen - 3;
-    memcpy (ret->sbuf, &str->sbuf[2], ret->slen);
+    GNUNET_memcpy (ret->sbuf, &str->sbuf[2], ret->slen);
     return;
   }
   sb_strdup (ret, str);
@@ -1417,12 +1421,12 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij,
 
       length_l = length;
       temp_a.sbuf = temp_a.abuf;
-      memcpy (temp_a.sbuf, R_last_kj->sbuf, length_l);
+      GNUNET_memcpy (temp_a.sbuf, R_last_kj->sbuf, length_l);
       temp_a.slen = length_l;
 
       length_r = R_last_kj->slen - length;
       temp_b.sbuf = temp_b.abuf;
-      memcpy (temp_b.sbuf, &R_last_kj->sbuf[length], length_r);
+      GNUNET_memcpy (temp_b.sbuf, &R_last_kj->sbuf[length], length_r);
       temp_b.slen = length_r;
 
       /* e|(ab)+ = (ab)* */
@@ -2010,8 +2014,8 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
       if ( (s1->accepting && !s2->accepting) ||
           (!s1->accepting && s2->accepting) )
       {
-       idx = s1->marked * state_cnt + s2->marked;
-        table[idx / 32] |= (1 << (idx % 32));
+       idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
+        table[idx / 32] |= (1U << (idx % 32));
       }
 
   /* Find all equal states */
@@ -2023,8 +2027,8 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
     {
       for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next)
       {
-       idx = s1->marked * state_cnt + s2->marked;
-        if (0 != (table[idx / 32] & (1 << (idx % 32))))
+       idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
+        if (0 != (table[idx / 32] & (1U << (idx % 32))))
           continue;
         num_equal_edges = 0;
         for (t1 = s1->transitions_head; NULL != t1; t1 = t1->next)
@@ -2037,12 +2041,12 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
              /* same edge, but targets definitively different, so we're different
                 as well */
              if (t1->to_state->marked > t2->to_state->marked)
-               idx1 = t1->to_state->marked * state_cnt + t2->to_state->marked;
+               idx1 = (unsigned long long) t1->to_state->marked * state_cnt + t2->to_state->marked;
              else
-               idx1 = t2->to_state->marked * state_cnt + t1->to_state->marked;
-             if (0 != (table[idx1 / 32] & (1 << (idx1 % 32))))
+               idx1 = (unsigned long long) t2->to_state->marked * state_cnt + t1->to_state->marked;
+             if (0 != (table[idx1 / 32] & (1U << (idx1 % 32))))
              {
-               table[idx / 32] |= (1 << (idx % 32));
+               table[idx / 32] |= (1U << (idx % 32));
                change = 1; /* changed a marker, need to run again */
              }
            }
@@ -2052,7 +2056,7 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
             (num_equal_edges != s2->transition_count) )
         {
           /* Make sure ALL edges of possible equal states are the same */
-         table[idx / 32] |= (1 << (idx % 32));
+         table[idx / 32] |= (1U << (idx % 32));
          change = 1;  /* changed a marker, need to run again */
         }
       }
@@ -2066,8 +2070,8 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
     for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2_next)
     {
       s2_next = s2->next;
-      idx = s1->marked * state_cnt + s2->marked;
-      if (0 == (table[idx / 32] & (1 << (idx % 32))))
+      idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
+      if (0 == (table[idx / 32] & (1U << (idx % 32))))
         automaton_merge_states (ctx, a, s1, s2);
     }
   }
@@ -3569,7 +3573,7 @@ store_all_states (void *cls,
   tmp->num_edges = num_edges;
   edges_size = sizeof (struct REGEX_BLOCK_Edge) * num_edges;
   tmp->edges = GNUNET_malloc (edges_size);
-  memcpy(tmp->edges, edges, edges_size);
+  GNUNET_memcpy(tmp->edges, edges, edges_size);
   GNUNET_CONTAINER_multihashmap_put (hm, key, tmp,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
 }