]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport rev. 39743 by lemburg]
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 29 Sep 2006 17:57:58 +0000 (17:57 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 29 Sep 2006 17:57:58 +0000 (17:57 +0000)
Bug fix for [ 1331062 ] utf 7 codec broken.

Backport candidate.

Misc/NEWS
Objects/unicodeobject.c

index 80aeba9156bc646cc016e568859c771b85af15cd..c3d8a126c7facf7743705ec763679fa357649b0d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.4.4c1?
 Core and builtins
 -----------------
 
+- Bug #1331062: Fix error in UTF-7 codec.
+
 - Bug #1365916: Fix an int/long mismatch in the sorted() built-in.
 
 - Fix memory leak of coding spec in Parser/tokenizer.c.
index bb6a7cbf515bba8806f0ad556ba7b894eb8dbabf..d65355a924296dd4011c809ed7f1cc17f9be82ba 100644 (file)
@@ -845,15 +845,23 @@ char utf7_special[128] = {
 
 };
 
+/* Note: The comparison (c) <= 0 is a trick to work-around gcc
+   warnings about the comparison always being false; since
+   utf7_special[0] is 1, we can safely make that one comparison
+   true  */
+
 #define SPECIAL(c, encodeO, encodeWS) \
-       (((c)>127 || utf7_special[(c)] == 1) || \
+    ((c) > 127 || (c) <= 0 || utf7_special[(c)] == 1 || \
         (encodeWS && (utf7_special[(c)] == 2)) || \
      (encodeO && (utf7_special[(c)] == 3)))
 
-#define B64(n)  ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(n) & 0x3f])
-#define B64CHAR(c) (isalnum(c) || (c) == '+' || (c) == '/')
-#define UB64(c)        ((c) == '+' ? 62 : (c) == '/' ? 63 : (c) >= 'a' ? \
-                        (c) - 71 : (c) >= 'A' ? (c) - 65 : (c) + 4)
+#define B64(n)  \
+    ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(n) & 0x3f])
+#define B64CHAR(c) \
+    (isalnum(c) || (c) == '+' || (c) == '/')
+#define UB64(c) \
+    ((c) == '+' ? 62 : (c) == '/' ? 63 : (c) >= 'a' ?                   \
+     (c) - 71 : (c) >= 'A' ? (c) - 65 : (c) + 4 )
 
 #define ENCODE(out, ch, bits) \
     while (bits >= 6) { \
@@ -866,8 +874,8 @@ char utf7_special[128] = {
         Py_UNICODE outCh = (Py_UNICODE) ((ch >> (bits-16)) & 0xffff); \
         bits -= 16; \
                if (surrogate) { \
-                       /* We have already generated an error for the high surrogate
-               so let's not bother seeing if the low surrogate is correct or not */\
+            /* We have already generated an error for the high surrogate \
+               so let's not bother seeing if the low surrogate is correct or not */ \
                        surrogate = 0; \
                } else if (0xDC00 <= outCh && outCh <= 0xDFFF) { \
             /* This is a surrogate pair. Unfortunately we can't represent \
@@ -878,7 +886,7 @@ char utf7_special[128] = {
                } else { \
                                *out++ = outCh; \
                } \
-    } \
+    }
 
 PyObject *PyUnicode_DecodeUTF7(const char *s,
                               int size,