From 056abd2059c65a3e908193aeae16fad98017437c Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 2 Dec 2012 13:20:44 +0000 Subject: Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2): http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974 --- lib/Basic/ConvertUTFWrapper.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/Basic/ConvertUTFWrapper.cpp') diff --git a/lib/Basic/ConvertUTFWrapper.cpp b/lib/Basic/ConvertUTFWrapper.cpp index a1b3f7f..6be3828 100644 --- a/lib/Basic/ConvertUTFWrapper.cpp +++ b/lib/Basic/ConvertUTFWrapper.cpp @@ -13,16 +13,19 @@ namespace clang { bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source, - char *&ResultPtr) { + char *&ResultPtr, const UTF8 *&ErrorPtr) { assert(WideCharWidth == 1 || WideCharWidth == 2 || WideCharWidth == 4); ConversionResult result = conversionOK; // Copy the character span over. if (WideCharWidth == 1) { - if (!isLegalUTF8String(reinterpret_cast(Source.begin()), - reinterpret_cast(Source.end()))) + const UTF8 *Pos = reinterpret_cast(Source.begin()); + if (!isLegalUTF8String(&Pos, reinterpret_cast(Source.end()))) { result = sourceIllegal; - memcpy(ResultPtr, Source.data(), Source.size()); - ResultPtr += Source.size(); + ErrorPtr = Pos; + } else { + memcpy(ResultPtr, Source.data(), Source.size()); + ResultPtr += Source.size(); + } } else if (WideCharWidth == 2) { const UTF8 *sourceStart = (const UTF8*)Source.data(); // FIXME: Make the type of the result buffer correct instead of @@ -34,6 +37,8 @@ bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source, &targetStart, targetStart + 2*Source.size(), flags); if (result == conversionOK) ResultPtr = reinterpret_cast(targetStart); + else + ErrorPtr = sourceStart; } else if (WideCharWidth == 4) { const UTF8 *sourceStart = (const UTF8*)Source.data(); // FIXME: Make the type of the result buffer correct instead of @@ -45,6 +50,8 @@ bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source, &targetStart, targetStart + 4*Source.size(), flags); if (result == conversionOK) ResultPtr = reinterpret_cast(targetStart); + else + ErrorPtr = sourceStart; } assert((result != targetExhausted) && "ConvertUTF8toUTFXX exhausted target buffer"); @@ -67,4 +74,3 @@ bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr) { } } // end namespace clang - -- cgit v1.1