Avoid pointer arithmetic in cfx_datetime.cpp
Convert to spans, which will hard check on OOB.
-- remove soft checks given the above.
Change-Id: I2c8f540b89e09f0e0121da264a3a747dff34de0f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96951
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Auto-Submit: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/cfx_datetime.cpp b/core/fxcrt/cfx_datetime.cpp
index 731b56a..90cb377 100644
--- a/core/fxcrt/cfx_datetime.cpp
+++ b/core/fxcrt/cfx_datetime.cpp
@@ -10,6 +10,7 @@
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_system.h"
#include "third_party/base/check.h"
+#include "third_party/base/span.h"
namespace {
@@ -26,11 +27,10 @@
int32_t DaysBeforeMonthInYear(int32_t iYear, uint8_t iMonth) {
DCHECK(iYear != 0);
- DCHECK(iMonth >= 1);
- DCHECK(iMonth <= 12);
-
- const int32_t* p =
- FX_IsLeapYear(iYear) ? kDaysBeforeLeapMonth : kDaysBeforeMonth;
+ pdfium::span<const int32_t> p = FX_IsLeapYear(iYear)
+ ? pdfium::make_span(kDaysBeforeLeapMonth)
+ : pdfium::make_span(kDaysBeforeMonth);
+ // Note: iMonth is one-based.
return p[iMonth - 1];
}
@@ -68,10 +68,10 @@
uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth) {
DCHECK(iYear != 0);
- DCHECK(iMonth >= 1);
- DCHECK(iMonth <= 12);
-
- const uint8_t* p = FX_IsLeapYear(iYear) ? kDaysPerLeapMonth : kDaysPerMonth;
+ pdfium::span<const uint8_t> p = FX_IsLeapYear(iYear)
+ ? pdfium::make_span(kDaysPerLeapMonth)
+ : pdfium::make_span(kDaysPerMonth);
+ // Note: iMonth is one-based.
return p[iMonth - 1];
}