summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 21:06:51 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 21:06:51 +0000
commitb1c4b7c58fb67ae83d51de7e740f52b11de7d6d6 (patch)
treef86d37d009ea1658a8feda28ab56b678fb872925 /base
parenta6ba0d2c133825c97c935cc9e0bec04d2b27c4bb (diff)
downloadchromium_src-b1c4b7c58fb67ae83d51de7e740f52b11de7d6d6.zip
chromium_src-b1c4b7c58fb67ae83d51de7e740f52b11de7d6d6.tar.gz
chromium_src-b1c4b7c58fb67ae83d51de7e740f52b11de7d6d6.tar.bz2
Fix a FORWARD_NULL defect reported by Coverity. We should
allow the src_url argument of Clipboard::ReadHTML and the html and base_url arguments of ClipboardUtil::CFHtmlToHtml to be NULL. Fix nits reported by cpplint.py. In Clipboard::SetGtkClipboard, use strdup to duplicate strings. R=tony BUG=http://crbug.com/17101 TEST=none Review URL: http://codereview.chromium.org/160247 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21888 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/clipboard_linux.cc11
-rw-r--r--base/clipboard_util.cc49
-rw-r--r--base/clipboard_win.cc6
3 files changed, 35 insertions, 31 deletions
diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc
index eb5012c..5b49796 100644
--- a/base/clipboard_linux.cc
+++ b/base/clipboard_linux.cc
@@ -135,9 +135,7 @@ void Clipboard::SetGtkClipboard() {
int i = 0;
for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin();
iter != clipboard_data_->end(); ++iter, ++i) {
- char* target_string = new char[iter->first.size() + 1];
- strcpy(target_string, iter->first.c_str());
- targets[i].target = target_string;
+ targets[i].target = strndup(iter->first.data(), iter->first.size());
targets[i].flags = 0;
targets[i].info = i;
}
@@ -148,7 +146,7 @@ void Clipboard::SetGtkClipboard() {
clipboard_data_);
for (size_t i = 0; i < clipboard_data_->size(); i++)
- delete[] targets[i].target;
+ free(targets[i].target);
}
void Clipboard::WriteText(const char* text_data, size_t text_len) {
@@ -269,7 +267,7 @@ void Clipboard::ReadText(string16* result) const {
gchar* text = gtk_clipboard_wait_for_text(clipboard_);
if (text == NULL)
- return;
+ return;
// TODO(estade): do we want to handle the possible error here?
UTF8ToUTF16(text, strlen(text), result);
@@ -281,7 +279,7 @@ void Clipboard::ReadAsciiText(std::string* result) const {
gchar* text = gtk_clipboard_wait_for_text(clipboard_);
if (text == NULL)
- return;
+ return;
result->assign(text);
g_free(text);
@@ -292,6 +290,7 @@ void Clipboard::ReadFile(FilePath* file) const {
}
// TODO(estade): handle different charsets.
+// TODO(port): set *src_url.
void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
markup->clear();
diff --git a/base/clipboard_util.cc b/base/clipboard_util.cc
index 3fd07c0..74f34e3 100644
--- a/base/clipboard_util.cc
+++ b/base/clipboard_util.cc
@@ -107,8 +107,7 @@ FORMATETC* ClipboardUtil::GetFilenameWFormat() {
return &format;
}
-FORMATETC* ClipboardUtil::GetFilenameFormat()
-{
+FORMATETC* ClipboardUtil::GetFilenameFormat() {
static UINT cf = RegisterClipboardFormat(CFSTR_FILENAMEA);
static FORMATETC format = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
return &format;
@@ -300,8 +299,8 @@ bool ClipboardUtil::GetPlainText(IDataObject* data_object,
ReleaseStgMedium(&store);
success = true;
} else {
- //If a file is dropped on the window, it does not provide either of the
- //plain text formats, so here we try to forcibly get a url.
+ // If a file is dropped on the window, it does not provide either of the
+ // plain text formats, so here we try to forcibly get a url.
std::wstring title;
success = GetUrl(data_object, plain_text, &title);
}
@@ -368,7 +367,7 @@ bool ClipboardUtil::GetFileContents(IDataObject* data_object,
&description))) {
ScopedHGlobal<FILEGROUPDESCRIPTOR> fgd(description.hGlobal);
// We expect there to be at least one file in here.
- DCHECK(fgd->cItems >= 1);
+ DCHECK_GE(fgd->cItems, 1);
filename->assign(fgd->fgd[0].cFileName);
ReleaseStgMedium(&description);
}
@@ -462,27 +461,31 @@ void ClipboardUtil::CFHtmlToHtml(const std::string& cf_html,
std::string* html,
std::string* base_url) {
// Obtain base_url if present.
- static std::string src_url_str("SourceURL:");
- size_t line_start = cf_html.find(src_url_str);
- if (line_start != std::string::npos) {
- size_t src_end = cf_html.find("\n", line_start);
- size_t src_start = line_start + src_url_str.length();
- if (src_end != std::string::npos && src_start != std::string::npos) {
- *base_url = cf_html.substr(src_start, src_end - src_start);
- TrimWhitespace(*base_url, TRIM_ALL, base_url);
+ if (base_url) {
+ static std::string src_url_str("SourceURL:");
+ size_t line_start = cf_html.find(src_url_str);
+ if (line_start != std::string::npos) {
+ size_t src_end = cf_html.find("\n", line_start);
+ size_t src_start = line_start + src_url_str.length();
+ if (src_end != std::string::npos && src_start != std::string::npos) {
+ *base_url = cf_html.substr(src_start, src_end - src_start);
+ TrimWhitespace(*base_url, TRIM_ALL, base_url);
+ }
}
}
// Find the markup between "<!--StartFragment -->" and "<!--EndFragment-->".
- std::string cf_html_lower = StringToLowerASCII(cf_html);
- size_t markup_start = cf_html_lower.find("<html", 0);
- size_t tag_start = cf_html.find("StartFragment", markup_start);
- size_t fragment_start = cf_html.find('>', tag_start) + 1;
- size_t tag_end = cf_html.rfind("EndFragment", std::string::npos);
- size_t fragment_end = cf_html.rfind('<', tag_end);
- if (fragment_start != std::string::npos &&
- fragment_end != std::string::npos) {
- *html = cf_html.substr(fragment_start, fragment_end - fragment_start);
- TrimWhitespace(*html, TRIM_ALL, html);
+ if (html) {
+ std::string cf_html_lower = StringToLowerASCII(cf_html);
+ size_t markup_start = cf_html_lower.find("<html", 0);
+ size_t tag_start = cf_html.find("StartFragment", markup_start);
+ size_t fragment_start = cf_html.find('>', tag_start) + 1;
+ size_t tag_end = cf_html.rfind("EndFragment", std::string::npos);
+ size_t fragment_end = cf_html.rfind('<', tag_end);
+ if (fragment_start != std::string::npos &&
+ fragment_end != std::string::npos) {
+ *html = cf_html.substr(fragment_start, fragment_end - fragment_start);
+ TrimWhitespace(*html, TRIM_ALL, html);
+ }
}
}
diff --git a/base/clipboard_win.cc b/base/clipboard_win.cc
index 684bec6..371e8f5 100644
--- a/base/clipboard_win.cc
+++ b/base/clipboard_win.cc
@@ -447,8 +447,10 @@ void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
::GlobalUnlock(data);
std::string markup_utf8;
- ClipboardUtil::CFHtmlToHtml(html_fragment, &markup_utf8, src_url);
- markup->assign(UTF8ToWide(markup_utf8));
+ ClipboardUtil::CFHtmlToHtml(html_fragment, markup ? &markup_utf8 : NULL,
+ src_url);
+ if (markup)
+ markup->assign(UTF8ToWide(markup_utf8));
}
void Clipboard::ReadBookmark(string16* title, std::string* url) const {