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:
trop[bot] 2024-09-30 14:40:42 -05:00 committed by GitHub
parent c8788f8217
commit e019b37231
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View file

@ -24,10 +24,9 @@ namespace extensions {
ElectronComponentExtensionResourceManager::
ElectronComponentExtensionResourceManager() {
AddComponentResourceEntries(kComponentExtensionResources,
kComponentExtensionResourcesSize);
AddComponentResourceEntries(kComponentExtensionResources);
#if BUILDFLAG(ENABLE_PDF_VIEWER)
AddComponentResourceEntries(kPdfResources, kPdfResourcesSize);
AddComponentResourceEntries(kPdfResources);
// Register strings for the PDF viewer, so that $i18n{} replacements work.
base::Value::Dict pdf_strings;
@ -80,20 +79,18 @@ ElectronComponentExtensionResourceManager::GetTemplateReplacementsForExtension(
}
void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
const webui::ResourcePath* entries,
size_t size) {
const base::span<const webui::ResourcePath> entries) {
base::FilePath gen_folder_path = base::FilePath().AppendASCII(
"@out_folder@/gen/chrome/browser/resources/");
gen_folder_path = gen_folder_path.NormalizePathSeparators();
for (size_t i = 0; i < size; ++i) {
base::FilePath resource_path =
base::FilePath().AppendASCII(entries[i].path);
for (const auto& entry : entries) {
base::FilePath resource_path = base::FilePath().AppendASCII(entry.path);
resource_path = resource_path.NormalizePathSeparators();
if (!gen_folder_path.IsParent(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 {
// 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
@ -102,7 +99,7 @@ void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
gen_folder_path.value().length()));
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;
}
}
}

View file

@ -10,6 +10,7 @@
#include <map>
#include <string>
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "extensions/browser/component_extension_resource_manager.h"
#include "ui/base/webui/resource_path.h"
@ -38,8 +39,8 @@ class ElectronComponentExtensionResourceManager
const std::string& extension_id) const override;
private:
void AddComponentResourceEntries(const webui::ResourcePath* entries,
size_t size);
void AddComponentResourceEntries(
base::span<const webui::ResourcePath> entries);
// A map from a resource path to the resource ID. Used by
// IsComponentExtensionResource.