From 28db414fa4aac8a2e722d7d7d03f057bf6cb176c Mon Sep 17 00:00:00 2001 From: "scc%netscape.com" Date: Sat, 1 Apr 2000 00:39:02 +0000 Subject: [PATCH] making string conversions explicit git-svn-id: svn://10.0.0.236/trunk@64827 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/caps/src/nsBasePrincipal.cpp | 2 +- mozilla/caps/src/nsCertificatePrincipal.cpp | 11 ++++++----- mozilla/caps/src/nsScriptSecurityManager.cpp | 4 +++- mozilla/caps/src/nsSystemPrincipal.cpp | 5 ++++- .../xpconnect/loader/mozJSComponentLoader.cpp | 4 +++- mozilla/netwerk/base/public/nsNetUtil.h | 2 +- mozilla/xpcom/build/nsXPComInit.cpp | 3 ++- mozilla/xpcom/ds/nsAtomTable.cpp | 3 ++- mozilla/xpcom/ds/nsHashtable.cpp | 4 ++-- mozilla/xpcom/ds/nsPersistentProperties.cpp | 10 ++++++---- mozilla/xpcom/ds/nsTextFormatter.cpp | 17 +++++++++++++---- mozilla/xpcom/io/nsFileSpec.cpp | 10 +++++----- mozilla/xpcom/io/nsFileSpecMac.cpp | 4 +++- mozilla/xpcom/io/nsIStringStream.cpp | 2 +- mozilla/xpcom/io/nsLocalFileMac.cpp | 4 ++-- mozilla/xpcom/io/nsUnicharInputStream.cpp | 3 ++- mozilla/xpcom/threads/nsEventQueue.cpp | 4 +++- 17 files changed, 59 insertions(+), 33 deletions(-) diff --git a/mozilla/caps/src/nsBasePrincipal.cpp b/mozilla/caps/src/nsBasePrincipal.cpp index 36072696dbf..f2e270c8166 100644 --- a/mozilla/caps/src/nsBasePrincipal.cpp +++ b/mozilla/caps/src/nsBasePrincipal.cpp @@ -243,7 +243,7 @@ AppendCapability(nsHashKey *aKey, void *aData, void *aStr) char value = (char)((unsigned int)aData) + '0'; nsCString *capStr = (nsCString*) aStr; capStr->Append(' '); - capStr->Append(((nsStringKey *) aKey)->GetString()); + capStr->AppendWithConversion(((nsStringKey *) aKey)->GetString()); capStr->Append('='); capStr->Append(value); return PR_TRUE; diff --git a/mozilla/caps/src/nsCertificatePrincipal.cpp b/mozilla/caps/src/nsCertificatePrincipal.cpp index 33a9917bf14..ef6089d29af 100644 --- a/mozilla/caps/src/nsCertificatePrincipal.cpp +++ b/mozilla/caps/src/nsCertificatePrincipal.cpp @@ -76,12 +76,13 @@ nsCertificatePrincipal::CanEnableCapability(const char *capability, NS_IMETHODIMP nsCertificatePrincipal::ToString(char **result) { + // STRING USE WARNING: perhaps |str| should be an |nsCAutoString|? -- scc nsAutoString str; - str += "[Certificate "; - str += mIssuerName; - str += ' '; - str += mSerialNumber; - str += ']'; + str.AppendWithConversion("[Certificate "); + str.AppendWithConversion(mIssuerName); + str.AppendWithConversion(' '); + str.AppendWithConversion(mSerialNumber); + str.AppendWithConversion(']'); *result = str.ToNewCString(); return (*result) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 944fda77392..3ea5266898e 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -784,7 +784,9 @@ Localize(char *genericString, nsString &result) } /* localize the given string */ - nsAutoString strtmp(genericString); + nsAutoString strtmp; + strtmp.AssignWithConversion(genericString); + PRUnichar *ptrv = nsnull; ret = bundle->GetStringFromName(strtmp.GetUnicode(), &ptrv); NS_RELEASE(bundle); diff --git a/mozilla/caps/src/nsSystemPrincipal.cpp b/mozilla/caps/src/nsSystemPrincipal.cpp index 608d5ea9f60..a894dfa0c18 100644 --- a/mozilla/caps/src/nsSystemPrincipal.cpp +++ b/mozilla/caps/src/nsSystemPrincipal.cpp @@ -44,7 +44,10 @@ NSBASEPRINCIPALS_RELEASE(nsSystemPrincipal); NS_IMETHODIMP nsSystemPrincipal::ToString(char **result) { - nsAutoString buf("[System]"); + // STRING USE WARNING: perhaps |buf| should be an |nsCAutoString|? -- scc + nsAutoString buf; + buf.AssignWithConversion("[System]"); + *result = buf.ToNewCString(); return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp index 39fd3bb6ba6..ef460a8cdd3 100644 --- a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -210,7 +210,9 @@ Reporter(JSContext *cx, const char *message, JSErrorReport *rep) * Got an error object; prepare appropriate-width versions of * various arguments to it. */ - nsAutoString fileUni(rep->filename); + nsAutoString fileUni; + fileUni.AssignWithConversion(rep->filename); + const PRUnichar *newFileUni = fileUni.ToNewUnicode(); PRUint32 column = rep->uctokenptr - rep->uclinebuf; diff --git a/mozilla/netwerk/base/public/nsNetUtil.h b/mozilla/netwerk/base/public/nsNetUtil.h index e8f4891e286..cd38fbed4aa 100644 --- a/mozilla/netwerk/base/public/nsNetUtil.h +++ b/mozilla/netwerk/base/public/nsNetUtil.h @@ -237,7 +237,7 @@ NS_MakeAbsoluteURI(nsString& result, nsAllocator::Free(specStr); if (NS_FAILED(rv)) return rv; - result = resultStr; + result.AssignWithConversion(resultStr); nsAllocator::Free(resultStr); return rv; } diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index 7c20681d05f..23234150660 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -574,7 +574,8 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr) rv = nsServiceManager::GetGlobalServiceManager(&mgr); if (NS_SUCCEEDED(rv)) { - nsAutoString topic = NS_XPCOM_SHUTDOWN_OBSERVER_ID; + nsAutoString topic; + topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID); (void) observerService->Notify(mgr, topic.GetUnicode(), nsnull); } } diff --git a/mozilla/xpcom/ds/nsAtomTable.cpp b/mozilla/xpcom/ds/nsAtomTable.cpp index c8ea19f3876..30c9eb31847 100644 --- a/mozilla/xpcom/ds/nsAtomTable.cpp +++ b/mozilla/xpcom/ds/nsAtomTable.cpp @@ -135,7 +135,8 @@ static PRIntn CompareKeys(const PRUnichar* k1, const PRUnichar* k2) NS_COM nsIAtom* NS_NewAtom(const char* isolatin1) { - nsAutoString tmp(isolatin1); + nsAutoString tmp; + tmp.AssignWithConversion(isolatin1); return NS_NewAtom(tmp.GetUnicode()); } diff --git a/mozilla/xpcom/ds/nsHashtable.cpp b/mozilla/xpcom/ds/nsHashtable.cpp index 1a07b1e0a2e..7e56eae06ff 100644 --- a/mozilla/xpcom/ds/nsHashtable.cpp +++ b/mozilla/xpcom/ds/nsHashtable.cpp @@ -250,7 +250,7 @@ void nsHashtable::Reset(nsHashtableEnumFunc destroyFunc, void* closure) nsStringKey::nsStringKey(const char* str) { - mStr.Assign(str); + mStr.AssignWithConversion(str); } nsStringKey::nsStringKey(const PRUnichar* str) @@ -263,7 +263,7 @@ nsStringKey::nsStringKey(const nsString& str) { } nsStringKey::nsStringKey(const nsCString& str) { - mStr.Assign(str); + mStr.AssignWithConversion(str); } nsStringKey::~nsStringKey(void) diff --git a/mozilla/xpcom/ds/nsPersistentProperties.cpp b/mozilla/xpcom/ds/nsPersistentProperties.cpp index 4c6a5016a0b..cd84057acc9 100644 --- a/mozilla/xpcom/ds/nsPersistentProperties.cpp +++ b/mozilla/xpcom/ds/nsPersistentProperties.cpp @@ -95,7 +95,9 @@ nsPersistentProperties::Load(nsIInputStream *aIn) PRInt32 c; nsresult ret; - nsAutoString uesc("x-u-escaped"); + nsAutoString uesc; + uesc.AssignWithConversion("x-u-escaped"); + ret = NS_NewConverterStream(&mIn, nsnull, aIn, 0, &uesc); if (ret != NS_OK) { #ifdef NS_DEBUG @@ -114,7 +116,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn) continue; } else { - nsAutoString key(""); + nsAutoString key; while ((c >= 0) && (c != '=') && (c != ':')) { key.Append((PRUnichar) c); c = Read(); @@ -125,7 +127,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn) char *trimThese = " \t"; key.Trim(trimThese, PR_FALSE, PR_TRUE); c = Read(); - nsAutoString value(""); + nsAutoString value; while ((c >= 0) && (c != '\r') && (c != '\n')) { if (c == '\\') { c = Read(); @@ -140,7 +142,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn) c = Read(); } value.Trim(trimThese, PR_TRUE, PR_TRUE); - nsAutoString oldValue(""); + nsAutoString oldValue; mSubclass->SetStringProperty(key, value, oldValue); } } diff --git a/mozilla/xpcom/ds/nsTextFormatter.cpp b/mozilla/xpcom/ds/nsTextFormatter.cpp index 537ba8e18fe..819c85ddddf 100644 --- a/mozilla/xpcom/ds/nsTextFormatter.cpp +++ b/mozilla/xpcom/ds/nsTextFormatter.cpp @@ -388,7 +388,9 @@ static int cvt_S(SprintfState *ss, const PRUnichar *s, int width, int prec, } /* and away we go */ - nsAutoString nullstr("(null)"); + nsAutoString nullstr; + nullstr.AssignWithConversion("(null)"); + return fill2(ss, s ? s : nullstr.GetUnicode(), slen, width, flags); } @@ -831,8 +833,13 @@ static int dosprintf(SprintfState *ss, const PRUnichar *fmt, va_list ap) } u; PRUnichar space = ' '; const PRUnichar *fmt0; - nsAutoString hex("0123456789abcdef"); - nsAutoString HEX("0123456789ABCDEF"); + + nsAutoString hex; + hex.AssignWithConversion("0123456789abcdef"); + + nsAutoString HEX; + HEX.AssignWithConversion("0123456789ABCDEF"); + const PRUnichar *hexp; int rv, i; struct NumArgState* nas = NULL; @@ -1389,7 +1396,9 @@ PRUnichar * nsTextFormatter::vsprintf_append(PRUnichar *last, const PRUnichar *f PRBool nsTextFormatter::SelfTest() { PRBool passed = PR_TRUE ; - nsAutoString fmt("%3$s %4$S %1$d %2$d"); + nsAutoString fmt; + fmt.AssignWithConversion("%3$s %4$S %1$d %2$d"); + char utf8[] = "Hello"; PRUnichar ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103}; int d=3; diff --git a/mozilla/xpcom/io/nsFileSpec.cpp b/mozilla/xpcom/io/nsFileSpec.cpp index d680c51e07c..774d9de5d23 100644 --- a/mozilla/xpcom/io/nsFileSpec.cpp +++ b/mozilla/xpcom/io/nsFileSpec.cpp @@ -1146,7 +1146,7 @@ void nsFileSpec::GetFileSystemCharset(nsString & fileSystemCharset) NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset"); if (NS_FAILED(rv)) - aCharset.Assign("ISO-8859-1"); + aCharset.AssignWithConversion("ISO-8859-1"); } fileSystemCharset = aCharset; } @@ -1198,7 +1198,7 @@ void nsFileSpec::GetNativePathString(nsString &nativePathString) { const char *path = GetCString(); if (nsnull == path) { - nativePathString.Assign(""); + nativePathString.SetLength(0); return; } else { @@ -1208,7 +1208,7 @@ void nsFileSpec::GetNativePathString(nsString &nativePathString) delete [] converted; } else - nativePathString.Assign(path); + nativePathString.AssignWithConversion(path); } } @@ -1219,7 +1219,7 @@ void nsFileSpec::GetLeafName(nsString &nativePathString) { char * path = GetLeafName(); if (nsnull == path) { - nativePathString.Assign(""); + nativePathString.SetLength(0); return; } else { PRUnichar *converted = ConvertFromFileSystemCharset(path); @@ -1228,7 +1228,7 @@ void nsFileSpec::GetLeafName(nsString &nativePathString) delete [] converted; } else - nativePathString.Assign(path); + nativePathString.AssignWithConversion(path); nsCRT::free(path); } diff --git a/mozilla/xpcom/io/nsFileSpecMac.cpp b/mozilla/xpcom/io/nsFileSpecMac.cpp index f37ed71d3fd..70a30756665 100644 --- a/mozilla/xpcom/io/nsFileSpecMac.cpp +++ b/mozilla/xpcom/io/nsFileSpecMac.cpp @@ -44,6 +44,7 @@ #include "nsFileSpec.h" #include "nsEscape.h" +#include "nsXPIDLString.h" #ifndef RHAPSODY @@ -1283,7 +1284,8 @@ nsFilePath::nsFilePath(const nsString& inString, PRBool inCreateDirs) void nsFilePath::operator = (const char* inString) //---------------------------------------------------------------------------------------- { - AssignFromPath(*this, nsAutoCString(inString), PR_FALSE); + nsXPIDLCString temp; temp = inString; + AssignFromPath(*this, temp, PR_FALSE); } //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsIStringStream.cpp b/mozilla/xpcom/io/nsIStringStream.cpp index e4596bd382f..6cdd00d0d9c 100644 --- a/mozilla/xpcom/io/nsIStringStream.cpp +++ b/mozilla/xpcom/io/nsIStringStream.cpp @@ -308,7 +308,7 @@ class StringImpl chars.Seek(PR_SEEK_SET, 0); PRUint32 newLength; chars.Available(&newLength); - mString.Assign(cstring, newLength); + mString.AssignWithConversion(cstring, newLength); // Set our const string also... delete [] (char*)mConstString; mConstString = cstring; diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index 09546bb58b6..25cacc0ad4d 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -938,7 +938,7 @@ nsLocalFile::InitWithPath(const char *filePath) // Just save the specified file path since we can't actually do anything // about turniung it into an FSSpec until the Create() method is called - mWorkingPath.SetString(filePath); + mWorkingPath.Assign(filePath); mInitType = eInitWithPath; @@ -2345,7 +2345,7 @@ NS_IMETHODIMP nsLocalFile::SetAppendedPath(const char *aPath) { MakeDirty(); - mAppendedPath.SetString(aPath); + mAppendedPath.Assign(aPath); return NS_OK; } diff --git a/mozilla/xpcom/io/nsUnicharInputStream.cpp b/mozilla/xpcom/io/nsUnicharInputStream.cpp index f757e07cd43..a934760f3d9 100644 --- a/mozilla/xpcom/io/nsUnicharInputStream.cpp +++ b/mozilla/xpcom/io/nsUnicharInputStream.cpp @@ -142,7 +142,8 @@ NS_NewB2UConverter(nsIUnicodeDecoder** aInstancePtrResult, // Create converter nsresult res; - nsAutoString defaultCharset("ISO-8859-1"); + nsAutoString defaultCharset; + defaultCharset.AssignWithConversion("ISO-8859-1"); if (aCharSet == nsnull) aCharSet = &defaultCharset; diff --git a/mozilla/xpcom/threads/nsEventQueue.cpp b/mozilla/xpcom/threads/nsEventQueue.cpp index 2576dff5404..01662919576 100644 --- a/mozilla/xpcom/threads/nsEventQueue.cpp +++ b/mozilla/xpcom/threads/nsEventQueue.cpp @@ -160,7 +160,9 @@ void nsEventQueueImpl::NotifyObservers(const char *aTopic) { nsresult rv; - nsAutoString topic(aTopic); + nsAutoString topic; + topic.AssignWithConversion(aTopic); + nsISupports *us = NS_STATIC_CAST(nsISupports *,(NS_STATIC_CAST(nsIEventQueue *,this))); NS_WITH_SERVICE(nsIObserverService, os, NS_OBSERVERSERVICE_PROGID, &rv);