Add NOTREACHED() to many //pdf switch statements
Given the following code snippets: void Foo(Enum e) { switch (e) { case ...: ... return; } } int Bar(Enum e) { switch (e) { case ...: ... return val; } } If the switch statements do not have a default case, since all defined enum values are handled, then undefined enum values can cause undefined behavior as suggested in https://abseil.io/tips/147. Avoid this by guarding the UB code path with NOTREACHED(). Clang actually generates "ud2" instructions in debug builds in the places where this CL adds NOTREACHED(). Whereas in release builds, Clang does whatever it wants. Also do IWYU for base/notreached.h in this directory. Change-Id: I4bbfe8ed091627608bc84f9658fe2c01dc47fec1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5813603 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Peter Boström <pbos@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347070}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1b958a9b45
commit
cc4a3146d3
@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/values.h"
|
||||
#include "pdf/draw_utils/coordinates.h"
|
||||
#include "ui/gfx/geometry/insets.h"
|
||||
@ -103,6 +104,7 @@ void DocumentLayout::ComputeLayout(const std::vector<gfx::Size>& page_sizes) {
|
||||
case PageSpread::kTwoUpOdd:
|
||||
return ComputeTwoUpOddLayout(page_sizes);
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
void DocumentLayout::ComputeOneUpLayout(
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "base/notreached.h"
|
||||
#include "pdf/ink/ink_brush.h"
|
||||
#include "pdf/ink/ink_brush_family.h"
|
||||
#include "pdf/ink/ink_brush_paint.h"
|
||||
@ -32,6 +33,7 @@ float GetCornerRounding(PdfInkBrush::Type type) {
|
||||
case PdfInkBrush::Type::kPen:
|
||||
return 1.0f;
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
float GetOpacity(PdfInkBrush::Type type) {
|
||||
@ -41,6 +43,7 @@ float GetOpacity(PdfInkBrush::Type type) {
|
||||
case PdfInkBrush::Type::kPen:
|
||||
return 1.0f;
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
std::unique_ptr<InkBrush> CreateInkBrush(PdfInkBrush::Type type,
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "base/check.h"
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/ranges/algorithm.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/values.h"
|
||||
@ -699,6 +700,7 @@ void PdfInkModule::ApplyUndoRedoCommands(
|
||||
return;
|
||||
}
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
void PdfInkModule::ApplyUndoRedoCommandsHelper(std::set<size_t> ids,
|
||||
|
@ -153,6 +153,7 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Undo() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Redo() {
|
||||
@ -177,6 +178,7 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Redo() {
|
||||
return GetEraseCommands(commands);
|
||||
}
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -777,11 +777,12 @@ void PdfViewWebPlugin::RotateView(blink::WebPlugin::RotationType type) {
|
||||
switch (type) {
|
||||
case blink::WebPlugin::RotationType::k90Clockwise:
|
||||
engine_->RotateClockwise();
|
||||
break;
|
||||
return;
|
||||
case blink::WebPlugin::RotationType::k90Counterclockwise:
|
||||
engine_->RotateCounterclockwise();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
bool PdfViewWebPlugin::ShouldDispatchImeEventsToPlugin() {
|
||||
@ -1539,7 +1540,7 @@ void PdfViewWebPlugin::HandleSaveMessage(const base::Value::Dict& message) {
|
||||
// using the plugin data.
|
||||
pdf_host_->SetPluginCanSave(true);
|
||||
SaveToBuffer(token);
|
||||
break;
|
||||
return;
|
||||
#else
|
||||
NOTREACHED();
|
||||
#endif // BUILDFLAG(ENABLE_INK)
|
||||
@ -1547,11 +1548,12 @@ void PdfViewWebPlugin::HandleSaveMessage(const base::Value::Dict& message) {
|
||||
pdf_host_->SetPluginCanSave(false);
|
||||
SaveToFile(token);
|
||||
pdf_host_->SetPluginCanSave(edit_mode_);
|
||||
break;
|
||||
return;
|
||||
case SaveRequestType::kEdited:
|
||||
SaveToBuffer(token);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::HandleSelectAllMessage(
|
||||
|
@ -2287,7 +2287,7 @@ void PDFiumEngine::HandleAccessibilityAction(
|
||||
ScrollBasedOnScrollAlignment(action_data.target_rect,
|
||||
action_data.horizontal_scroll_alignment,
|
||||
action_data.vertical_scroll_alignment);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case AccessibilityAction::kDoDefaultAction: {
|
||||
if (PageIndexInBounds(action_data.page_index)) {
|
||||
@ -2300,11 +2300,11 @@ void PDFiumEngine::HandleAccessibilityAction(
|
||||
WindowOpenDisposition::CURRENT_TAB);
|
||||
}
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case AccessibilityAction::kScrollToGlobalPoint: {
|
||||
ScrollToGlobalPoint(action_data.target_rect, action_data.target_point);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case AccessibilityAction::kSetSelection: {
|
||||
if (IsPageCharacterIndexInBounds(action_data.selection_start_index) &&
|
||||
@ -2312,15 +2312,16 @@ void PDFiumEngine::HandleAccessibilityAction(
|
||||
SetSelection(action_data.selection_start_index,
|
||||
action_data.selection_end_index);
|
||||
gfx::Rect target_rect = action_data.target_rect;
|
||||
if (GetVisibleRect().Contains(target_rect))
|
||||
return;
|
||||
client_->ScrollBy(GetScreenRect(target_rect).OffsetFromOrigin());
|
||||
if (!GetVisibleRect().Contains(target_rect)) {
|
||||
client_->ScrollBy(GetScreenRect(target_rect).OffsetFromOrigin());
|
||||
}
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case AccessibilityAction::kNone:
|
||||
NOTREACHED();
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
std::string PDFiumEngine::GetLinkAtPosition(const gfx::Point& point) {
|
||||
@ -4171,6 +4172,7 @@ bool PDFiumEngine::HandleTabEventWithModifiers(int modifiers) {
|
||||
return !!FORM_OnKeyDown(form(), pages_[last_focused_page_]->GetPage(),
|
||||
FWL_VKEY_Tab, modifiers);
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
bool PDFiumEngine::HandleTabForward(int modifiers) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/memory/raw_span.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/numerics/checked_math.h"
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/notreached.h"
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -51,6 +52,7 @@ bool PDFiumPermissions::HasPermission(DocumentPermission permission) const {
|
||||
// Check the same printing bit for all printing permissions.
|
||||
return HasPermissionBits(kPDFPermissionBit03PrintMask);
|
||||
}
|
||||
NOTREACHED();
|
||||
} else {
|
||||
// Security handler revision 3+ have different rules for interpreting the
|
||||
// bits in `permission_bits_`.
|
||||
@ -65,6 +67,7 @@ bool PDFiumPermissions::HasPermission(DocumentPermission permission) const {
|
||||
return HasPermissionBits(kPDFPermissionBit03PrintMask |
|
||||
kPDFPermissionBit12PrintHighQualityMask);
|
||||
}
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user