fixes bug 239405 "strchr, strrchr, etc. implicit const_cast can cause problems for shared string buffers" r=bienvenu sr=dbaron a=chofmann

This commit is contained in:
darin%meer.net 2004-04-03 17:16:17 +00:00
Родитель 7616ea0c1a
Коммит a3645b33e5
13 изменённых файлов: 25 добавлений и 22 удалений

Просмотреть файл

@ -147,7 +147,7 @@ nsSoundDatasource::GetTarget(nsIRDFResource *source,
if (property == kNC_Name.get()) {
nsCOMPtr<nsIRDFLiteral> name;
if (strcmp(value.get(), DEFAULT_SOUND_URL)) {
char *lastSlash = strrchr(value.get(), '/');
const char *lastSlash = strrchr(value.get(), '/');
// turn "file://C|/winnt/media/foo.wav" into "foo".
nsCAutoString soundName(lastSlash + 1);
soundName.Truncate(soundName.Length() - WAV_EXTENSION_LENGTH);
@ -350,7 +350,7 @@ nsSoundDatasource::GetTargets(nsIRDFResource *source,
else if (property == kNC_Name.get()) {
nsCOMPtr<nsIRDFLiteral> name;
if (strcmp(value.get(), DEFAULT_SOUND_URL)) {
char *lastSlash = strrchr(value.get(), '/');
const char *lastSlash = strrchr(value.get(), '/');
// turn "file://C|/winnt/media/foo.wav" into "foo".
nsCAutoString soundName(lastSlash + 1);
soundName.Truncate(soundName.Length() - WAV_EXTENSION_LENGTH);

Просмотреть файл

@ -428,10 +428,10 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetSpec(nsACString &aSpec)
NS_IMETHODIMP nsMsgMailNewsUrl::SetSpec(const nsACString &aSpec)
{
const nsPromiseFlatCString &spec = PromiseFlatCString(aSpec);
nsCAutoString spec(aSpec);
// Parse out "filename" attribute if present.
char *start, *end;
start = PL_strcasestr(spec.get(),FILENAME_PART);
start = PL_strcasestr(spec.BeginWriting(),FILENAME_PART);
if (start)
{ // Make sure we only get our own value.
end = PL_strcasestr((char*)(start+FILENAME_PART_LEN),"&");

Просмотреть файл

@ -3077,7 +3077,7 @@ nsMsgComposeSendListener::RemoveCurrentDraftMessage(nsIMsgCompose *compObj, PRBo
NS_ASSERTION(imapFolder, "The draft folder MUST be an imap folder in order to mark the msg delete!");
if (NS_SUCCEEDED(rv) && imapFolder)
{
char * str = PL_strstr(curDraftIdURL.get(), "#");
const char * str = PL_strstr(curDraftIdURL.get(), "#");
NS_ASSERTION(str, "Failed to get current draft id url");
if (str)
{

Просмотреть файл

@ -4123,7 +4123,7 @@ BuildURLAttachmentData(nsIURI *url)
{
int attachCount = 2; // one entry and one empty entry
nsMsgAttachmentData *attachments = nsnull;
char *theName = nsnull;
const char *theName = nsnull;
if (!url)
return nsnull;
@ -4137,7 +4137,7 @@ BuildURLAttachmentData(nsIURI *url)
url->GetSpec(spec);
if (!spec.IsEmpty())
{
theName = (char *)strrchr(spec.get(), '/');
theName = strrchr(spec.get(), '/');
}
if (!theName)

Просмотреть файл

@ -321,7 +321,8 @@ NS_IMETHODIMP nsPop3Service::NewURI(const nsACString &aSpec,
popSpec += ":";
popSpec.AppendInt(port);
popSpec += "?";
const char *uidl = PL_strstr(PromiseFlatCString(aSpec).get(), "uidl=");
const nsCString &flatSpec = PromiseFlatCString(aSpec);
const char *uidl = PL_strstr(flatSpec.get(), "uidl=");
if (!uidl) return NS_ERROR_FAILURE;
popSpec += uidl;
nsCOMPtr<nsIUrlListener> urlListener = do_QueryInterface(folder, &rv);

Просмотреть файл

@ -609,11 +609,13 @@ nsMimeBaseEmitter::UpdateCharacterSet(const char *aCharset)
if (NS_SUCCEEDED(mChannel->GetContentType(contentType)) && !contentType.IsEmpty())
{
char *cPtr = (char *) PL_strcasestr(contentType.get(), "charset=");
char *cBegin = contentType.BeginWriting();
const char *cPtr = PL_strcasestr(cBegin, "charset=");
if (cPtr)
{
char *ptr = (char *) contentType.get();
char *ptr = cBegin;
while (*ptr)
{
if ( (*ptr == ' ') || (*ptr == ';') )
@ -629,8 +631,8 @@ nsMimeBaseEmitter::UpdateCharacterSet(const char *aCharset)
}
}
// have to recompute strlen since contentType could have an embedded null byte
mChannel->SetContentType(nsDependentCString(contentType.get()));
// have to set content-type since it could have an embedded null byte
mChannel->SetContentType(nsDependentCString(cBegin));
mChannel->SetContentCharset(nsDependentCString(aCharset));
}
}

Просмотреть файл

@ -982,7 +982,7 @@ nsresult nsNNTPProtocol::OpenCacheEntry()
nsCAutoString urlSpec;
mailnewsUrl->GetAsciiSpec(urlSpec);
// for now, truncate of the query part so we don't duplicate urls in the cache...
char * anchor = (char *)strrchr(urlSpec.get(), '?');
char * anchor = (char *)strrchr(urlSpec.BeginWriting(), '?');
if (anchor)
*anchor = '\0';
return cacheSession->AsyncOpenCacheEntry(urlSpec.get(), nsICache::ACCESS_READ_WRITE, this);

Просмотреть файл

@ -99,7 +99,7 @@ nsDataChannel::ParseData() {
if (NS_FAILED(rv)) return rv;
// move past "data:"
const char *buffer = strstr(spec.get(), "data:");
char *buffer = (char *) strstr(spec.BeginWriting(), "data:");
if (!buffer) {
// malfored url
return NS_ERROR_MALFORMED_URI;
@ -107,13 +107,13 @@ nsDataChannel::ParseData() {
buffer += 5;
// First, find the start of the data
char *comma = PL_strchr(buffer, ',');
char *comma = strchr(buffer, ',');
if (!comma) return NS_ERROR_FAILURE;
*comma = '\0';
// determine if the data is base64 encoded.
char *base64 = PL_strstr(buffer, ";base64");
char *base64 = strstr(buffer, ";base64");
if (base64) {
lBase64 = PR_TRUE;
*base64 = '\0';
@ -125,7 +125,7 @@ nsDataChannel::ParseData() {
mContentCharset = NS_LITERAL_CSTRING("US-ASCII");
} else {
// everything else is content type
char *semiColon = PL_strchr(buffer, ';');
char *semiColon = (char *) strchr(buffer, ';');
if (semiColon)
*semiColon = '\0';

Просмотреть файл

@ -651,7 +651,7 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) {
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
}
bndry = strstr(delimiter.get(), "boundary");
bndry = strstr(delimiter.BeginWriting(), "boundary");
if (!bndry) return NS_ERROR_FAILURE;
bndry = strchr(bndry, '=');

Просмотреть файл

@ -1162,7 +1162,7 @@ nsGlobalHistory::MatchHost(nsIMdbRow *aRow,
// now try for a domain match, if necessary
if (hostInfo->entireDomain) {
// do a reverse-search to match the end of the string
char *domain = PL_strrstr(urlHost.get(), hostInfo->host);
const char *domain = PL_strrstr(urlHost.get(), hostInfo->host);
// now verify that we're matching EXACTLY the domain, and
// not some random string inside the hostname

Просмотреть файл

@ -1085,7 +1085,7 @@ NS_IMETHODIMP nsDragService::NativeDrop(PDRAGINFO pdinfo, HWND hwnd,
if (isUrl &&
pditem->hstrTargetName &&
NS_SUCCEEDED(GetAtom(pditem->hstrTargetName, getter_Copies(titleText))))
for (char* ptr=strchr(titleText.get(),'\n'); ptr; ptr=strchr(ptr, '\n'))
for (char* ptr=strchr(titleText.BeginWriting(),'\n'); ptr; ptr=strchr(ptr, '\n'))
*ptr = ' ';
rv = NativeDataToTransferable( dropText.get(), titleText.get(), isUrl);

Просмотреть файл

@ -1846,7 +1846,7 @@ nsLocalFile::IsExecutable(PRBool *_retval)
GetNativePath(path);
// Get extension.
char* ext = ::strrchr( path.get(), '.' );
char* ext = ::strrchr( path.BeginWriting(), '.' );
if ( ext ) {
// Convert extension to lower case.
for( char *p = ext; *p; p++ ) {

Просмотреть файл

@ -1145,7 +1145,7 @@ nsGlobalHistory::MatchHost(nsIMdbRow *aRow,
// now try for a domain match, if necessary
if (hostInfo->entireDomain) {
// do a reverse-search to match the end of the string
char *domain = PL_strrstr(urlHost.get(), hostInfo->host);
const char *domain = PL_strrstr(urlHost.get(), hostInfo->host);
// now verify that we're matching EXACTLY the domain, and
// not some random string inside the hostname