From 09fcbbb1f0d380b9b44d67c543036a36b8d0343e Mon Sep 17 00:00:00 2001 From: "mcafee%netscape.com" Date: Wed, 24 Mar 1999 09:06:37 +0000 Subject: [PATCH] Initializing some variables, protecting against null dereferences for new cut & paste platforms (gtk). git-svn-id: svn://10.0.0.236/trunk@24987 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsPresShell.cpp | 19 ++++++++++++++----- mozilla/layout/html/base/src/nsPresShell.cpp | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 88c544217f4..cb7a72fe616 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -1566,20 +1566,29 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) nsAutoString strBuf; ((nsHTMLToTXTSinkStream*)sink)->GetStringBuffer(strBuf); - nsIClipboard* clipboard; + nsIClipboard* clipboard = 0; nsresult rv = nsServiceManager::GetService(kCClipboardCID, kIClipboardIID, (nsISupports **)&clipboard); - nsITransferable * trans; + nsITransferable * trans = 0; rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, kITransferableIID, (void**) &trans); if (nsnull != trans) { //trans->AddDataFlavor("text/xif", "XIF Format"); trans->AddDataFlavor(kTextMime, "Text Format"); + } else { + printf("PresShell::DoCopy(), trans is null.\n"); } - trans->SetTransferString(strBuf); - clipboard->SetTransferable(trans, nsnull); - clipboard->SetClipboard(); + if(trans) { + trans->SetTransferString(strBuf); + } + + if(clipboard) { + clipboard->SetTransferable(trans, nsnull); + clipboard->SetClipboard(); + } else { + printf("PresShell::DoCopy(), clipboard instance is null.\n"); + } NS_IF_RELEASE(clipboard); NS_IF_RELEASE(trans); diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 88c544217f4..cb7a72fe616 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -1566,20 +1566,29 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) nsAutoString strBuf; ((nsHTMLToTXTSinkStream*)sink)->GetStringBuffer(strBuf); - nsIClipboard* clipboard; + nsIClipboard* clipboard = 0; nsresult rv = nsServiceManager::GetService(kCClipboardCID, kIClipboardIID, (nsISupports **)&clipboard); - nsITransferable * trans; + nsITransferable * trans = 0; rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, kITransferableIID, (void**) &trans); if (nsnull != trans) { //trans->AddDataFlavor("text/xif", "XIF Format"); trans->AddDataFlavor(kTextMime, "Text Format"); + } else { + printf("PresShell::DoCopy(), trans is null.\n"); } - trans->SetTransferString(strBuf); - clipboard->SetTransferable(trans, nsnull); - clipboard->SetClipboard(); + if(trans) { + trans->SetTransferString(strBuf); + } + + if(clipboard) { + clipboard->SetTransferable(trans, nsnull); + clipboard->SetClipboard(); + } else { + printf("PresShell::DoCopy(), clipboard instance is null.\n"); + } NS_IF_RELEASE(clipboard); NS_IF_RELEASE(trans);