From 5c57933509aedb46399d320da16dfcc3e5acf28d Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Mon, 5 Jan 2015 11:53:18 -0800 Subject: XFA: merge patch from CL 729293003, use FX_ArraySize for safety Note that the merge of this fix to XFA found six bugs. Five were fixed in https://codereview.chromium.org/826573003 and one was fixed in https://codereview.chromium.org/831293002. These bugs are now impossible to compile. 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. TBR=bo_xu@foxitsoftware.com, tsepez@chromium.org Review URL: https://codereview.chromium.org/818193004 --- fpdfsdk/include/javascript/JS_Define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fpdfsdk/include/javascript') diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index 8ead492548..6b7af41d5f 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -599,7 +599,7 @@ if (JS_DefineGlobalConst(pRuntime,JS_WIDESTRING(const_name),JS_NewString(pRuntim /* ======================================== GLOBAL ARRAYS ============================================ */ #define DEFINE_GLOBAL_ARRAY(pRuntime)\ -int size = sizeof(ArrayContent) / sizeof(FX_LPCWSTR);\ +int size = FX_ArraySize(ArrayContent);\ \ CJS_Array array(pRuntime);\ for (int i=0; i