You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2001/06/19 18:18:07 UTC
cvs commit: xml-xerces/c/src/util/Transcoders/Iconv IconvTransService.cpp
knoaman 01/06/19 09:18:07
Modified: c/src/util/Transcoders/Iconv IconvTransService.cpp
Log:
Bug fix - handle maxBytes > length(toTranscode)
Revision Changes Path
1.22 +16 -6 xml-xerces/c/src/util/Transcoders/Iconv/IconvTransService.cpp
Index: IconvTransService.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/Transcoders/Iconv/IconvTransService.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- IconvTransService.cpp 2001/03/09 21:31:02 1.21
+++ IconvTransService.cpp 2001/06/19 16:18:04 1.22
@@ -55,7 +55,7 @@
*/
/*
- * $Id: IconvTransService.cpp,v 1.21 2001/03/09 21:31:02 tng Exp $
+ * $Id: IconvTransService.cpp,v 1.22 2001/06/19 16:18:04 knoaman Exp $
*/
@@ -325,20 +325,25 @@
return true;
}
+ unsigned int wLent = getWideCharLength(toTranscode);
wchar_t tmpWideCharArr[gTempBuffArraySize];
wchar_t* allocatedArray = 0;
wchar_t* wideCharBuf = 0;
+ if (wLent > maxBytes) {
+ wLent = maxBytes;
+ }
+
if (maxBytes >= gTempBuffArraySize)
wideCharBuf = allocatedArray = new wchar_t[maxBytes + 1];
else
wideCharBuf = tmpWideCharArr;
- for (unsigned int i = 0; i < maxBytes; i++)
+ for (unsigned int i = 0; i < wLent; i++)
{
wideCharBuf[i] = toTranscode[i];
}
- wideCharBuf[maxBytes] = 0x00;
+ wideCharBuf[wLent] = 0x00;
// Ok, go ahead and try the transcoding. If it fails, then ...
if (::wcstombs(toFill, wideCharBuf, maxBytes) == -1)
@@ -348,7 +353,7 @@
}
// Cap it off just in case
- toFill[maxBytes] = 0;
+ toFill[wLent] = 0;
delete [] allocatedArray;
return true;
}
@@ -412,10 +417,15 @@
return true;
}
+ unsigned int len = calcRequiredSize(toTranscode);
wchar_t tmpWideCharArr[gTempBuffArraySize];
wchar_t* allocatedArray = 0;
wchar_t* wideCharBuf = 0;
+ if (len > maxChars) {
+ len = maxChars;
+ }
+
if (maxChars >= gTempBuffArraySize)
wideCharBuf = allocatedArray = new wchar_t[maxChars + 1];
else
@@ -427,11 +437,11 @@
return false;
}
- for (unsigned int i = 0; i < maxChars; i++)
+ for (unsigned int i = 0; i < len; i++)
{
toFill[i] = (XMLCh) wideCharBuf[i];
}
- toFill[maxChars] = 0x00;
+ toFill[len] = 0x00;
delete [] allocatedArray;
return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org