This could do with a comment about how the innocent looking "u8" there
is critical to the "<=" doing the right thing on machines with signed
chars...

Done.  Patch as applied is attached.

zw
# 
# old_revision [d51ee38d33e87702c503331f5366f9341f2457a4]
# 
# patch "constants.cc"
#  from [942d3eebad05095d859d2641150968f01f37c95e]
#    to [b812f3fff900905f174e164024e18c52ff8ffdad]
# 
# patch "constants.hh"
#  from [7812034aa4a4a35decd8018d849102c06623bcd4]
#    to [c5fe8274ac31f96c9cc610e6f6ee8cbed2079aa7]
# 
# patch "paths.cc"
#  from [4c98560ebccf3c70cfa26b985403a0a3fd66fb90]
#    to [86aafbfd4a3385965d283a07b57c61431f7356cd]
# 
============================================================
--- constants.cc	942d3eebad05095d859d2641150968f01f37c95e
+++ constants.cc	b812f3fff900905f174e164024e18c52ff8ffdad
@@ -110,22 +110,6 @@
 
   string const regex_legal_key_name_bytes("([EMAIL PROTECTED])");
 
-  // all the ASCII characters (bytes) which are illegal in a (file|local)_path
-
-  char const illegal_path_bytes_arr[33] =
-    {
-      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-      0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
-      0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-      0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
-      0x7f, 0x00
-    }
-  ;
-
-  char const * const illegal_path_bytes =
-  illegal_path_bytes_arr
-  ;
-
   // merkle tree / netcmd / netsync related stuff
 
   size_t const merkle_fanout_bits = 4;
============================================================
--- constants.hh	7812034aa4a4a35decd8018d849102c06623bcd4
+++ constants.hh	c5fe8274ac31f96c9cc610e6f6ee8cbed2079aa7
@@ -89,9 +89,6 @@
   // boost regex that matches the bytes in legal_key_name_bytes
   extern std::string const regex_legal_key_name_bytes;
 
-  // all the ASCII characters (bytes) which are illegal in a (file|local)_path
-  extern char const * const illegal_path_bytes;
-
   // remaining constants are related to netsync protocol
 
   // number of bytes in the hash used in netsync
============================================================
--- paths.cc	4c98560ebccf3c70cfa26b985403a0a3fd66fb90
+++ paths.cc	86aafbfd4a3385965d283a07b57c61431f7356cd
@@ -138,25 +138,15 @@
 static inline bool
 has_bad_chars(string const & path)
 {
-  static bool bad_chars_init(false);
-  static u8 bad_table[128] = {0};
-  if (UNLIKELY(!bad_chars_init))
+  for (string::const_iterator c = path.begin(); LIKELY(c != path.end()); c++)
     {
-      string bad_chars = string("\\") + constants::illegal_path_bytes + string(1, '\0');
-      for (string::const_iterator b = bad_chars.begin(); b != bad_chars.end(); b++)
-        {
-          u8 x = (u8)*b;
-          I((x) < sizeof(bad_table));
-          bad_table[x] = 1;
-        }
-      bad_chars_init = true;
-    }
-
-  for (string::const_iterator c = path.begin(); c != path.end(); c++)
-    {
+      // char is often a signed type; convert to unsigned to ensure that
+      // bytes 0x80-0xff are considered > 0x1f.
       u8 x = (u8)*c;
-      if (x < sizeof(bad_table) && bad_table[x])
-          return true;
+      // 0x5c is '\\'; we use the hex constant to make the dependency on
+      // ASCII encoding explicit.
+      if (UNLIKELY(x <= 0x1f || x == 0x5c || x == 0x7f))
+        return true;
     }
   return false;
 }
_______________________________________________
Monotone-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/monotone-devel

Reply via email to