fix: -Wunsafe-buffer-usage warnings in AddComponentResourceEntries() (#44031)
fix: -Wunsafe-buffer-usage warnings in ElectronComponentExtensionResourceManager::AddComponentResourceEntries() just replace pointer-and-length args with a span Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
c8788f8217
commit
e019b37231
2 changed files with 10 additions and 12 deletions
|
@ -24,10 +24,9 @@ namespace extensions {
|
||||||
|
|
||||||
ElectronComponentExtensionResourceManager::
|
ElectronComponentExtensionResourceManager::
|
||||||
ElectronComponentExtensionResourceManager() {
|
ElectronComponentExtensionResourceManager() {
|
||||||
AddComponentResourceEntries(kComponentExtensionResources,
|
AddComponentResourceEntries(kComponentExtensionResources);
|
||||||
kComponentExtensionResourcesSize);
|
|
||||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
AddComponentResourceEntries(kPdfResources, kPdfResourcesSize);
|
AddComponentResourceEntries(kPdfResources);
|
||||||
|
|
||||||
// Register strings for the PDF viewer, so that $i18n{} replacements work.
|
// Register strings for the PDF viewer, so that $i18n{} replacements work.
|
||||||
base::Value::Dict pdf_strings;
|
base::Value::Dict pdf_strings;
|
||||||
|
@ -80,20 +79,18 @@ ElectronComponentExtensionResourceManager::GetTemplateReplacementsForExtension(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
|
void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
|
||||||
const webui::ResourcePath* entries,
|
const base::span<const webui::ResourcePath> entries) {
|
||||||
size_t size) {
|
|
||||||
base::FilePath gen_folder_path = base::FilePath().AppendASCII(
|
base::FilePath gen_folder_path = base::FilePath().AppendASCII(
|
||||||
"@out_folder@/gen/chrome/browser/resources/");
|
"@out_folder@/gen/chrome/browser/resources/");
|
||||||
gen_folder_path = gen_folder_path.NormalizePathSeparators();
|
gen_folder_path = gen_folder_path.NormalizePathSeparators();
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i) {
|
for (const auto& entry : entries) {
|
||||||
base::FilePath resource_path =
|
base::FilePath resource_path = base::FilePath().AppendASCII(entry.path);
|
||||||
base::FilePath().AppendASCII(entries[i].path);
|
|
||||||
resource_path = resource_path.NormalizePathSeparators();
|
resource_path = resource_path.NormalizePathSeparators();
|
||||||
|
|
||||||
if (!gen_folder_path.IsParent(resource_path)) {
|
if (!gen_folder_path.IsParent(resource_path)) {
|
||||||
DCHECK(!base::Contains(path_to_resource_id_, resource_path));
|
DCHECK(!base::Contains(path_to_resource_id_, resource_path));
|
||||||
path_to_resource_id_[resource_path] = entries[i].id;
|
path_to_resource_id_[resource_path] = entry.id;
|
||||||
} else {
|
} else {
|
||||||
// If the resource is a generated file, strip the generated folder's path,
|
// If the resource is a generated file, strip the generated folder's path,
|
||||||
// so that it can be served from a normal URL (as if it were not
|
// so that it can be served from a normal URL (as if it were not
|
||||||
|
@ -102,7 +99,7 @@ void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
|
||||||
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
|
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
|
||||||
gen_folder_path.value().length()));
|
gen_folder_path.value().length()));
|
||||||
DCHECK(!base::Contains(path_to_resource_id_, effective_path));
|
DCHECK(!base::Contains(path_to_resource_id_, effective_path));
|
||||||
path_to_resource_id_[effective_path] = entries[i].id;
|
path_to_resource_id_[effective_path] = entry.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/containers/span.h"
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "extensions/browser/component_extension_resource_manager.h"
|
#include "extensions/browser/component_extension_resource_manager.h"
|
||||||
#include "ui/base/webui/resource_path.h"
|
#include "ui/base/webui/resource_path.h"
|
||||||
|
@ -38,8 +39,8 @@ class ElectronComponentExtensionResourceManager
|
||||||
const std::string& extension_id) const override;
|
const std::string& extension_id) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddComponentResourceEntries(const webui::ResourcePath* entries,
|
void AddComponentResourceEntries(
|
||||||
size_t size);
|
base::span<const webui::ResourcePath> entries);
|
||||||
|
|
||||||
// A map from a resource path to the resource ID. Used by
|
// A map from a resource path to the resource ID. Used by
|
||||||
// IsComponentExtensionResource.
|
// IsComponentExtensionResource.
|
||||||
|
|
Loading…
Reference in a new issue