diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-06-21 12:39:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-21 12:39:22 (GMT) |
commit | 5ff7132313eb651107b179d20218dfe5d4e47f13 (patch) | |
tree | c75f190454b750d8b03fdf05d5ed5c0d621e499d /Modules/expat/xmltok.c | |
parent | f3e8209152dffd201620c5b5936946a9250ac359 (diff) | |
download | cpython-5ff7132313eb651107b179d20218dfe5d4e47f13.zip cpython-5ff7132313eb651107b179d20218dfe5d4e47f13.tar.gz cpython-5ff7132313eb651107b179d20218dfe5d4e47f13.tar.bz2 |
bpo-30694: Upgrade Modules/expat/ to libexpat 2.2.1 (#2300)
New file: Modules/expat/siphash.h.
Diffstat (limited to 'Modules/expat/xmltok.c')
-rw-r--r-- | Modules/expat/xmltok.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/Modules/expat/xmltok.c b/Modules/expat/xmltok.c index a29d9e2..cdf0720 100644 --- a/Modules/expat/xmltok.c +++ b/Modules/expat/xmltok.c @@ -4,19 +4,13 @@ #include <stddef.h> -#ifdef WIN32 +#ifdef _WIN32 #include "winconfig.h" -#elif defined(MACOS_CLASSIC) -#include "macconfig.h" -#elif defined(__amigaos__) -#include "amigaconfig.h" -#elif defined(__WATCOMC__) -#include "watcomconfig.h" #else #ifdef HAVE_EXPAT_CONFIG_H #include <expat_config.h> #endif -#endif /* ndef WIN32 */ +#endif /* ndef _WIN32 */ #include "expat_external.h" #include "internal.h" @@ -369,24 +363,24 @@ utf8_toUtf8(const ENCODING *UNUSED_P(enc), const char **fromP, const char *fromLim, char **toP, const char *toLim) { - enum XML_Convert_Result res = XML_CONVERT_COMPLETED; char *to; const char *from; - if (fromLim - *fromP > toLim - *toP) { - /* Avoid copying partial characters. */ - res = XML_CONVERT_OUTPUT_EXHAUSTED; - fromLim = *fromP + (toLim - *toP); - align_limit_to_full_utf8_characters(*fromP, &fromLim); - } + const char *fromLimInitial = fromLim; + + /* Avoid copying partial characters. */ + align_limit_to_full_utf8_characters(*fromP, &fromLim); + for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++) *to = *from; *fromP = from; *toP = to; - if ((to == toLim) && (from < fromLim)) + if (fromLim < fromLimInitial) + return XML_CONVERT_INPUT_INCOMPLETE; + else if ((to == toLim) && (from < fromLim)) return XML_CONVERT_OUTPUT_EXHAUSTED; else - return res; + return XML_CONVERT_COMPLETED; } static enum XML_Convert_Result PTRCALL @@ -402,7 +396,7 @@ utf8_toUtf16(const ENCODING *enc, case BT_LEAD2: if (fromLim - from < 2) { res = XML_CONVERT_INPUT_INCOMPLETE; - break; + goto after; } *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); from += 2; @@ -410,7 +404,7 @@ utf8_toUtf16(const ENCODING *enc, case BT_LEAD3: if (fromLim - from < 3) { res = XML_CONVERT_INPUT_INCOMPLETE; - break; + goto after; } *to++ = (unsigned short)(((from[0] & 0xf) << 12) | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); @@ -441,6 +435,8 @@ utf8_toUtf16(const ENCODING *enc, break; } } + if (from < fromLim) + res = XML_CONVERT_OUTPUT_EXHAUSTED; after: *fromP = from; *toP = to; |