diff options
author | Bruce Dawson <brucedawson@google.com> | 2014-12-08 16:19:45 -0800 |
---|---|---|
committer | Bruce Dawson <brucedawson@google.com> | 2014-12-08 16:19:45 -0800 |
commit | 4429eaa2d0c5f07118a57418a469ee39461cd4c5 (patch) | |
tree | b748c58c4ead58f65cf0d56545d7c6b38c19b3ec /core/include/fxcrt/fx_string.h | |
parent | b69da0b96ffdad124efd1b48d51c617bb216a98e (diff) | |
download | pdfium-4429eaa2d0c5f07118a57418a469ee39461cd4c5.tar.xz |
Replace manual/error-prone/hard-to-verify arraysize calculations with safe FX_ArraySize macro.
pdfium has numerous places where the number of elements in an array is
calculated with expressions like:
sizeof(cFormats)/sizeof(FX_LPCWSTR)
This is suboptimal because it is verbose, it is easy to get wrong, and
it cannot be determined through casual inspection whether the code is
correct. It will give incorrect results if cFormats is a pointer instead
of an array and it will give incorrect results if FX_LPCWSTR is not the
type of the array elements.
The FX_WSTRC macro in fx_string.h which I fixed was particularly scary
because it would silently misbehave if passed a pointer.
The FX_ArraySize macro which I have added and started using (taken from
arraysize in v8's macros.h) is easier to use and will always give correct
results. If passed a pointer it will fail to compile.
For this change I only fixed instances of sizeof(FX_LPCWSTR). There
appear to be about 150 other places in the pdfium code that could
benefit from using FX_ArraySize.
R=bo_xu@foxitsoftware.com, tsepez@chromium.org
Review URL: https://codereview.chromium.org/729293003
Diffstat (limited to 'core/include/fxcrt/fx_string.h')
-rw-r--r-- | core/include/fxcrt/fx_string.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h index 47e8ecdf1e..44c6fc53ff 100644 --- a/core/include/fxcrt/fx_string.h +++ b/core/include/fxcrt/fx_string.h @@ -597,7 +597,7 @@ private: } }; typedef const CFX_WideStringC& FX_WSTR; -#define FX_WSTRC(wstr) CFX_WideStringC(wstr, sizeof(wstr) / sizeof(FX_WCHAR) - 1) +#define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) struct CFX_StringDataW { long m_nRefs; |