diff -r acd3cd4aaceb -r 2efc27d87e1c utilitylibraries/libutils/src/chartodescriptor16.cpp --- a/utilitylibraries/libutils/src/chartodescriptor16.cpp Tue Aug 31 16:54:36 2010 +0300 +++ b/utilitylibraries/libutils/src/chartodescriptor16.cpp Wed Sep 01 12:36:54 2010 +0100 @@ -24,7 +24,7 @@ * Converts a character stream to TBuf16 * * @param aSrc is char*, aDes is the reference to the descriptor - * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer, -7 is EInvalidMBSSequence) + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer) */ EXPORT_C int CharToTbuf16(const char* aSrc, TDes16& aDes) @@ -46,7 +46,7 @@ return EInsufficientMemory; } } - wchar_t *WcharString = new wchar_t[ilen+1]; + wchar_t *WcharString = new wchar_t[ilen]; if(!WcharString) { return EInsufficientSystemMemory; @@ -69,7 +69,7 @@ * Converts a character stream to HBufc16 * * @param aSrc is char*, aDes is the reference to the descriptor - * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer, -6 is EUseNewMaxL, -7 is EInvalidMBSSequence) + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer) */ EXPORT_C int CharToHbufc16(const char* aSrc, HBufC16* aDes) @@ -121,17 +121,17 @@ /** * Converts a character stream to TPtr16 * - * @param aSrc is char*, wPtr is wchar_t*, aDes is the reference to the descriptor - * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer, -7 is EInvalidMBSSequence) + * @param aSrc is char*, aDes is the reference to the descriptor + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer) */ -EXPORT_C int CharpToTptr16(const char* aSrc, TPtr16& aDes) +EXPORT_C int CharpToTptr16(const char* aSrc, wchar_t *wPtr, TPtr16& aDes) { int retval = ESuccess; unsigned int ilen =0 , ilendes = 0; int minusone = -1; - if (!aSrc) + if (!aSrc || !wPtr) { return EInvalidPointer; } @@ -140,37 +140,29 @@ ilen = strlen(aSrc); ilendes = aDes.MaxLength(); - if (ilendes < ilen) + if (ilendes < ilen ) { return EInsufficientMemory; } } - wchar_t *wPtr = new wchar_t[ilen+1]; - - if (!wPtr) - { - return EInsufficientMemory; - } - if(minusone != mbstowcs((wchar_t *)wPtr, (const char*)aSrc, ilen )) { - aDes.Copy((unsigned short *)wPtr, ilen); + aDes.Set((unsigned short *)wPtr, ilen , ilendes); } else { retval = EInvalidMBSSequence; } - delete[] wPtr; return retval; } /** * Converts a character stream to TPtrc16 * - * @param aSrc is char*, cPtr is wchar_t*, aDes is the reference to the descriptor - * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer, -7 is EInvalidMBSSequence) + * @param aSrc is char*, aDes is the reference to the descriptor + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer) */ EXPORT_C int CharpToTptrc16(char* aSrc ,wchar_t* cPtr, TPtrC16& aDes) @@ -202,7 +194,7 @@ * Converts a character stream to RBuf16 * * @param aSrc is char*, aDes is the reference to the descriptor - * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer, -7 is EInvalidMBSSequence) + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer) */ @@ -225,7 +217,10 @@ if(minusone != mbstowcs(buf, aSrc, ilen)) { - aDes.Copy((const unsigned short *)buf, ilen); + if (KErrNone == aDes.Create(ilen)) + { + aDes.Copy((const unsigned short *)buf, ilen); + } } else {