oleaut32: Use the ARRAY_SIZE() macro.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2018-08-29 21:05:39 +02:00 committed by Alexandre Julliard
parent 56b3304a01
commit a1e0a029b0
8 changed files with 90 additions and 115 deletions

View File

@ -122,9 +122,7 @@ static inline bstr_t *bstr_from_str(BSTR str)
static inline bstr_cache_entry_t *get_cache_entry_from_idx(unsigned cache_idx)
{
return bstr_cache_enabled && cache_idx < sizeof(bstr_cache)/sizeof(*bstr_cache)
? bstr_cache + cache_idx
: NULL;
return bstr_cache_enabled && cache_idx < ARRAY_SIZE(bstr_cache) ? bstr_cache + cache_idx : NULL;
}
static inline bstr_cache_entry_t *get_cache_entry(size_t size)
@ -304,7 +302,7 @@ void WINAPI SysFreeString(BSTR str)
}
}
if(cache_entry->cnt < sizeof(cache_entry->buf)/sizeof(*cache_entry->buf)) {
if(cache_entry->cnt < ARRAY_SIZE(cache_entry->buf)) {
cache_entry->buf[(cache_entry->head+cache_entry->cnt) % BUCKET_BUFFER_SIZE] = bstr;
cache_entry->cnt++;

View File

@ -591,7 +591,7 @@ static void realize_font(OLEFontImpl *This)
if(This->gdiFont)
{
old_font = SelectObject(hdc, This->gdiFont);
GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
GetTextFaceW(hdc, ARRAY_SIZE(text_face), text_face);
SelectObject(hdc, old_font);
dec_int_ref(This->gdiFont);
This->gdiFont = 0;
@ -645,7 +645,7 @@ static void realize_font(OLEFontImpl *This)
/* Fixup the name and charset properties so that they match the
selected font */
old_font = SelectObject(get_dc(), This->gdiFont);
GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
GetTextFaceW(hdc, ARRAY_SIZE(text_face), text_face);
if(lstrcmpiW(text_face, This->description.lpstrName))
{
HeapFree(GetProcessHeap(), 0, This->description.lpstrName);

View File

@ -2395,7 +2395,7 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
if (strncmpW(szURLorPath, file, 5) == 0) {
DWORD size;
hRes = CoInternetParseUrl(szURLorPath, PARSE_PATH_FROM_URL, 0, path_buf,
sizeof(path_buf)/sizeof(WCHAR), &size, 0);
ARRAY_SIZE(path_buf), &size, 0);
if (FAILED(hRes))
return hRes;

View File

@ -387,8 +387,8 @@ _get_typeinfo_for_iid(REFIID riid, ITypeInfo **typeinfo)
*typeinfo = NULL;
moduleW[0] = 0;
if (!actctx_get_typelib_module(riid, moduleW, sizeof(moduleW)/sizeof(moduleW[0]))) {
hres = reg_get_typelib_module(riid, moduleW, sizeof(moduleW)/sizeof(moduleW[0]));
if (!actctx_get_typelib_module(riid, moduleW, ARRAY_SIZE(moduleW))) {
hres = reg_get_typelib_module(riid, moduleW, ARRAY_SIZE(moduleW));
if (FAILED(hres))
return hres;
}
@ -1470,9 +1470,9 @@ static DWORD WINAPI xCall(int method, void **args)
/* Need them for hack below */
memset(names,0,sizeof(names));
if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,ARRAY_SIZE(names),&nrofnames))
nrofnames = 0;
if (nrofnames > sizeof(names)/sizeof(names[0]))
if (nrofnames > ARRAY_SIZE(names))
ERR("Need more names!\n");
xargs = (DWORD *)(args + 1);
@ -2125,8 +2125,8 @@ TMStubImpl_Invoke(
/* Need them for hack below */
memset(names,0,sizeof(names));
ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
if (nrofnames > sizeof(names)/sizeof(names[0])) {
ITypeInfo_GetNames(tinfo,fdesc->memid,names,ARRAY_SIZE(names),&nrofnames);
if (nrofnames > ARRAY_SIZE(names)) {
ERR("Need more names!\n");
}

View File

@ -328,7 +328,7 @@ static HRESULT query_typelib_path( REFGUID guid, WORD wMaj, WORD wMin,
return TYPE_E_LIBNOTREGISTERED;
nameW = (WCHAR*)((BYTE*)data.lpSectionBase + tlib->name_offset);
len = SearchPathW( NULL, nameW, NULL, sizeof(Path)/sizeof(WCHAR), Path, NULL );
len = SearchPathW( NULL, nameW, NULL, ARRAY_SIZE( Path ), Path, NULL );
if (!len) return TYPE_E_LIBNOTREGISTERED;
TRACE_(typelib)("got path from context %s\n", debugstr_w(Path));
@ -969,11 +969,11 @@ enddeleteloop:
/* check if there is anything besides the FLAGS/HELPDIR keys.
If there is, we don't delete them */
tmpLength = sizeof(subKeyName)/sizeof(WCHAR);
tmpLength = ARRAY_SIZE(subKeyName);
deleteOtherStuff = TRUE;
i = 0;
while(RegEnumKeyExW(key, i++, subKeyName, &tmpLength, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
tmpLength = sizeof(subKeyName)/sizeof(WCHAR);
tmpLength = ARRAY_SIZE(subKeyName);
/* if its not FLAGS or HELPDIR, then we must keep the rest of the key */
if (!strcmpW(subKeyName, FLAGSW)) continue;
@ -7751,7 +7751,7 @@ static BOOL CALLBACK search_res_tlb(HMODULE hModule, LPCWSTR lpszType, LPWSTR lp
if (!(len = GetModuleFileNameW(hModule, szPath, MAX_PATH)))
return TRUE;
if (snprintfW(szPath + len, sizeof(szPath)/sizeof(WCHAR) - len, formatW, LOWORD(lpszName)) < 0)
if (snprintfW(szPath + len, ARRAY_SIZE(szPath) - len, formatW, LOWORD(lpszName)) < 0)
return TRUE;
ret = LoadTypeLibEx(szPath, REGKIND_NONE, &pTLib);

View File

@ -449,8 +449,7 @@ static inline const BYTE *VARIANT_GetNamedFormat(LPCWSTR lpszFormat)
LPCNAMED_FORMAT fmt;
key.name = lpszFormat;
fmt = bsearch(&key, VARIANT_NamedFormats,
sizeof(VARIANT_NamedFormats)/sizeof(NAMED_FORMAT),
fmt = bsearch(&key, VARIANT_NamedFormats, ARRAY_SIZE(VARIANT_NamedFormats),
sizeof(NAMED_FORMAT), FormatCompareFn);
return fmt ? fmt->format : NULL;
}
@ -764,7 +763,7 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
TRACE("time sep\n");
}
else if ((*pFormat == 'a' || *pFormat == 'A') &&
!strncmpiW(pFormat, szAMPM, sizeof(szAMPM)/sizeof(WCHAR)))
!strncmpiW(pFormat, szAMPM, ARRAY_SIZE(szAMPM)))
{
/* Date formats: System AM/PM designation
* Other formats: Literal
@ -772,8 +771,8 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
*/
header->type = FMT_TYPE_DATE;
NEED_SPACE(sizeof(BYTE));
pFormat += sizeof(szAMPM)/sizeof(WCHAR);
if (!strncmpW(pFormat, szampm, sizeof(szampm)/sizeof(WCHAR)))
pFormat += ARRAY_SIZE(szAMPM);
if (!strncmpW(pFormat, szampm, ARRAY_SIZE(szampm)))
*pOut++ = FMT_DATE_AMPM_SYS2;
else
*pOut++ = FMT_DATE_AMPM_SYS1;
@ -811,8 +810,7 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
*pLastHours = *pLastHours + 2;
TRACE("A/P\n");
}
else if (*pFormat == 'a' &&
!strncmpW(pFormat, szamSlashpm, sizeof(szamSlashpm)/sizeof(WCHAR)))
else if (*pFormat == 'a' && !strncmpW(pFormat, szamSlashpm, ARRAY_SIZE(szamSlashpm)))
{
/* Date formats: lowercase AM or PM designation
* Other formats: Literal
@ -820,14 +818,13 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
*/
header->type = FMT_TYPE_DATE;
NEED_SPACE(sizeof(BYTE));
pFormat += sizeof(szamSlashpm)/sizeof(WCHAR);
pFormat += ARRAY_SIZE(szamSlashpm);
*pOut++ = FMT_DATE_AMPM_LOWER;
if (pLastHours)
*pLastHours = *pLastHours + 2;
TRACE("AM/PM\n");
}
else if (*pFormat == 'A' &&
!strncmpW(pFormat, szAMSlashPM, sizeof(szAMSlashPM)/sizeof(WCHAR)))
else if (*pFormat == 'A' && !strncmpW(pFormat, szAMSlashPM, ARRAY_SIZE(szAMSlashPM)))
{
/* Date formats: Uppercase AM or PM designation
* Other formats: Literal
@ -835,7 +832,7 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
*/
header->type = FMT_TYPE_DATE;
NEED_SPACE(sizeof(BYTE));
pFormat += sizeof(szAMSlashPM)/sizeof(WCHAR);
pFormat += ARRAY_SIZE(szAMSlashPM);
*pOut++ = FMT_DATE_AMPM_UPPER;
TRACE("AM/PM\n");
}
@ -847,7 +844,7 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
*/
header->type = FMT_TYPE_DATE;
NEED_SPACE(sizeof(BYTE));
pFormat += sizeof(szAMSlashPM)/sizeof(WCHAR);
pFormat += ARRAY_SIZE(szAMSlashPM);
*pOut++ = FMT_DATE_GENERAL;
TRACE("gen date\n");
}
@ -989,14 +986,14 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
fmt_state &= ~FMT_STATE_OPEN_COPY;
}
else if ((*pFormat == 't' || *pFormat == 'T') &&
!strncmpiW(pFormat, szTTTTT, sizeof(szTTTTT)/sizeof(WCHAR)))
!strncmpiW(pFormat, szTTTTT, ARRAY_SIZE(szTTTTT)))
{
/* Date formats: System time specifier
* Other formats: Literal
* Types the format if found
*/
header->type = FMT_TYPE_DATE;
pFormat += sizeof(szTTTTT)/sizeof(WCHAR);
pFormat += ARRAY_SIZE(szTTTTT);
NEED_SPACE(sizeof(BYTE));
*pOut++ = FMT_DATE_TIME_SYS;
fmt_state &= ~FMT_STATE_OPEN_COPY;
@ -1316,8 +1313,7 @@ static HRESULT VARIANT_FormatNumber(LPVARIANT pVarIn, LPOLESTR lpszFormat,
if (numHeader->flags & FMT_FLAG_THOUSANDS)
{
if (!GetLocaleInfoW(lcid, LOCALE_STHOUSAND, thousandSeparator,
sizeof(thousandSeparator)/sizeof(WCHAR)))
if (!GetLocaleInfoW(lcid, LOCALE_STHOUSAND, thousandSeparator, ARRAY_SIZE(thousandSeparator)))
{
thousandSeparator[0] = ',';
thousandSeparator[1] = 0;
@ -1555,8 +1551,7 @@ VARIANT_FormatNumber_Bool:
}
if (localeValue)
{
if (GetLocaleInfoW(lcid, localeValue, pBuff,
sizeof(buff)/sizeof(WCHAR)-(pBuff-buff)))
if (GetLocaleInfoW(lcid, localeValue, pBuff, ARRAY_SIZE(buff)-(pBuff-buff)))
{
TRACE("added %s\n", debugstr_w(pBuff));
while (*pBuff)
@ -1875,8 +1870,7 @@ static HRESULT VARIANT_FormatDate(LPVARIANT pVarIn, LPOLESTR lpszFormat,
if (localeValue)
{
*pBuff = '\0';
if (GetLocaleInfoW(lcid, localeValue, pBuff,
sizeof(buff)/sizeof(WCHAR)-(pBuff-buff)))
if (GetLocaleInfoW(lcid, localeValue, pBuff, ARRAY_SIZE(buff)-(pBuff-buff)))
{
TRACE("added %s\n", debugstr_w(pBuff));
while (*pBuff)
@ -1892,9 +1886,8 @@ static HRESULT VARIANT_FormatDate(LPVARIANT pVarIn, LPOLESTR lpszFormat,
{
WCHAR fmt_buff[80];
if (!GetLocaleInfoW(lcid, dwFmt, fmt_buff, sizeof(fmt_buff)/sizeof(WCHAR)) ||
!get_date_format(lcid, 0, &udate.st, fmt_buff, pBuff,
sizeof(buff)/sizeof(WCHAR)-(pBuff-buff)))
if (!GetLocaleInfoW(lcid, dwFmt, fmt_buff, ARRAY_SIZE(fmt_buff)) ||
!get_date_format(lcid, 0, &udate.st, fmt_buff, pBuff, ARRAY_SIZE(buff)-(pBuff-buff)))
{
hRes = E_INVALIDARG;
goto VARIANT_FormatDate_Exit;
@ -2293,8 +2286,7 @@ HRESULT WINAPI VarFormatNumber(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT
{
WCHAR grouping[16];
grouping[2] = '\0';
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, grouping,
sizeof(grouping)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, grouping, ARRAY_SIZE(grouping));
numfmt.Grouping = grouping[2] == '2' ? 32 : grouping[0] - '0';
}
else if (nGrouping == -1)
@ -2310,14 +2302,11 @@ HRESULT WINAPI VarFormatNumber(LPVARIANT pVarIn, INT nDigits, INT nLeading, INT
numfmt.NegativeOrder = 1; /* 1 = "-xxx" */
numfmt.lpDecimalSep = decimal;
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal,
sizeof(decimal)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal, ARRAY_SIZE(decimal));
numfmt.lpThousandSep = thousands;
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousands,
sizeof(thousands)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousands, ARRAY_SIZE(thousands));
if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, V_BSTR(&vStr), &numfmt,
buff, sizeof(buff)/sizeof(WCHAR)))
if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, V_BSTR(&vStr), &numfmt, buff, ARRAY_SIZE(buff)))
{
*pbstrOut = SysAllocString(buff);
if (!*pbstrOut)
@ -2473,8 +2462,7 @@ HRESULT WINAPI VarFormatCurrency(LPVARIANT pVarIn, INT nDigits, INT nLeading,
{
WCHAR grouping[16];
grouping[2] = '\0';
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, grouping,
sizeof(grouping)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, grouping, ARRAY_SIZE(grouping));
numfmt.Grouping = grouping[2] == '2' ? 32 : grouping[0] - '0';
}
else if (nGrouping == -1)
@ -2492,18 +2480,14 @@ HRESULT WINAPI VarFormatCurrency(LPVARIANT pVarIn, INT nDigits, INT nLeading,
GETLOCALENUMBER(LOCALE_ICURRENCY, PositiveOrder);
numfmt.lpDecimalSep = decimal;
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal,
sizeof(decimal)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal, ARRAY_SIZE(decimal));
numfmt.lpThousandSep = thousands;
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, thousands,
sizeof(thousands)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, thousands, ARRAY_SIZE(thousands));
numfmt.lpCurrencySymbol = currency;
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, currency,
sizeof(currency)/sizeof(WCHAR));
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, currency, ARRAY_SIZE(currency));
/* use NLS as per VarFormatNumber() */
if (GetCurrencyFormatW(LOCALE_USER_DEFAULT, 0, V_BSTR(&vStr), &numfmt,
buff, sizeof(buff)/sizeof(WCHAR)))
if (GetCurrencyFormatW(LOCALE_USER_DEFAULT, 0, V_BSTR(&vStr), &numfmt, buff, ARRAY_SIZE(buff)))
{
*pbstrOut = SysAllocString(buff);
if (!*pbstrOut)

View File

@ -1549,7 +1549,7 @@ static void VARIANT_GetLocalisedNumberChars(VARIANT_NUMBER_CHARS *lpChars, LCID
/* Local currency symbols are often 2 characters */
lpChars->cCurrencyLocal2 = '\0';
switch(GetLocaleInfoW(lcid, lctype|LOCALE_SCURRENCY, buff, sizeof(buff)/sizeof(WCHAR)))
switch(GetLocaleInfoW(lcid, lctype|LOCALE_SCURRENCY, buff, ARRAY_SIZE(buff)))
{
case 3: lpChars->cCurrencyLocal2 = buff[1]; /* Fall through */
case 2: lpChars->cCurrencyLocal = buff[0];
@ -1610,7 +1610,7 @@ HRESULT WINAPI VarParseNumFromStr(OLECHAR *lpszStr, LCID lcid, ULONG dwFlags,
VARIANT_NUMBER_CHARS chars;
BYTE rgbTmp[1024];
DWORD dwState = B_EXPONENT_START|B_INEXACT_ZEROS;
int iMaxDigits = sizeof(rgbTmp) / sizeof(BYTE);
int iMaxDigits = ARRAY_SIZE(rgbTmp);
int cchUsed = 0;
TRACE("(%s,%d,0x%08x,%p,%p)\n", debugstr_w(lpszStr), lcid, dwFlags, pNumprs, rgbDig);

View File

@ -95,7 +95,7 @@ static HRESULT VARIANT_NumberFromBstr(OLECHAR* pStrIn, LCID lcid, ULONG ulFlags,
BYTE rgb[1024];
/* Use VarParseNumFromStr/VarNumFromParseNum as MSDN indicates */
np.cDig = sizeof(rgb) / sizeof(BYTE);
np.cDig = ARRAY_SIZE(rgb);
np.dwInFlags = NUMPRS_STD;
hRet = VarParseNumFromStr(pStrIn, lcid, ulFlags, &np, rgb);
@ -4496,15 +4496,15 @@ static HRESULT VARIANT_DecScale(const DECIMAL** ppDecLeft,
di.scale -= i;
remainder = 0;
while (i-- > 0 && !VARIANT_int_iszero(di.bitsnum, sizeof(di.bitsnum)/sizeof(DWORD)))
while (i-- > 0 && !VARIANT_int_iszero(di.bitsnum, ARRAY_SIZE(di.bitsnum)))
{
remainder = VARIANT_int_divbychar(di.bitsnum, sizeof(di.bitsnum)/sizeof(DWORD), 10);
remainder = VARIANT_int_divbychar(di.bitsnum, ARRAY_SIZE(di.bitsnum), 10);
if (remainder > 0) WARN("losing significant digits (remainder %u)...\n", remainder);
}
/* round up the result - native oleaut32 does this */
if (remainder >= 5) {
for (remainder = 1, i = 0; i < sizeof(di.bitsnum)/sizeof(DWORD) && remainder; i++) {
for (remainder = 1, i = 0; i < ARRAY_SIZE(di.bitsnum) && remainder; i++) {
ULONGLONG digit = di.bitsnum[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
di.bitsnum[i] = digit & 0xFFFFFFFF;
@ -4743,7 +4743,7 @@ static int VARIANT_DI_mul(const VARIANT_DI * a, const VARIANT_DI * b, VARIANT_DI
memset(running, 0, sizeof(running));
/* count number of leading zero-bytes in operand A */
for (mulstart = sizeof(a->bitsnum)/sizeof(DWORD) - 1; mulstart >= 0 && !a->bitsnum[mulstart]; mulstart--);
for (mulstart = ARRAY_SIZE(a->bitsnum) - 1; mulstart >= 0 && !a->bitsnum[mulstart]; mulstart--);
if (mulstart < 0) {
/* result is 0, because operand A is 0 */
result->scale = 0;
@ -4757,7 +4757,7 @@ static int VARIANT_DI_mul(const VARIANT_DI * a, const VARIANT_DI * b, VARIANT_DI
ULONG iOverflowMul;
int iB;
for (iOverflowMul = 0, iB = 0; iB < sizeof(b->bitsnum)/sizeof(DWORD); iB++) {
for (iOverflowMul = 0, iB = 0; iB < ARRAY_SIZE(b->bitsnum); iB++) {
ULONG iRV;
int iR;
@ -4789,11 +4789,10 @@ static int VARIANT_DI_mul(const VARIANT_DI * a, const VARIANT_DI * b, VARIANT_DI
This operation *will* lose significant digits of the result because
all the factors of 10 were consumed by the previous operation.
*/
while (result->scale > 0 && !VARIANT_int_iszero(
running + sizeof(result->bitsnum) / sizeof(DWORD),
(sizeof(running) - sizeof(result->bitsnum)) / sizeof(DWORD))) {
while (result->scale > 0 && !VARIANT_int_iszero(running + ARRAY_SIZE(result->bitsnum),
ARRAY_SIZE(running) - ARRAY_SIZE(result->bitsnum))) {
remainder = VARIANT_int_divbychar(running, sizeof(running) / sizeof(DWORD), 10);
remainder = VARIANT_int_divbychar(running, ARRAY_SIZE(running), 10);
if (remainder > 0) WARN("losing significant digits (remainder %u)...\n", remainder);
result->scale--;
}
@ -4801,7 +4800,7 @@ static int VARIANT_DI_mul(const VARIANT_DI * a, const VARIANT_DI * b, VARIANT_DI
/* round up the result - native oleaut32 does this */
if (remainder >= 5) {
unsigned int i;
for (remainder = 1, i = 0; i < sizeof(running)/sizeof(DWORD) && remainder; i++) {
for (remainder = 1, i = 0; i < ARRAY_SIZE(running) && remainder; i++) {
ULONGLONG digit = running[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
running[i] = digit & 0xFFFFFFFF;
@ -4811,9 +4810,8 @@ static int VARIANT_DI_mul(const VARIANT_DI * a, const VARIANT_DI * b, VARIANT_DI
/* Signal overflow if scale == 0 and 256-bit result still overflows,
and copy result bits into result structure
*/
r_overflow = !VARIANT_int_iszero(
running + sizeof(result->bitsnum)/sizeof(DWORD),
(sizeof(running) - sizeof(result->bitsnum))/sizeof(DWORD));
r_overflow = !VARIANT_int_iszero(running + ARRAY_SIZE(result->bitsnum),
ARRAY_SIZE(running) - ARRAY_SIZE(result->bitsnum));
memcpy(result->bitsnum, running, sizeof(result->bitsnum));
}
return r_overflow;
@ -4831,7 +4829,7 @@ static BOOL VARIANT_DI_tostringW(const VARIANT_DI * a, WCHAR * s, unsigned int n
unsigned int i;
/* place negative sign */
if (!VARIANT_int_iszero(a->bitsnum, sizeof(a->bitsnum) / sizeof(DWORD)) && a->sign) {
if (!VARIANT_int_iszero(a->bitsnum, ARRAY_SIZE(a->bitsnum)) && a->sign) {
if (n > 0) {
*s++ = '-';
n--;
@ -4849,8 +4847,8 @@ static BOOL VARIANT_DI_tostringW(const VARIANT_DI * a, WCHAR * s, unsigned int n
i = 0;
memcpy(quotient, a->bitsnum, sizeof(a->bitsnum));
while (!overflow && !VARIANT_int_iszero(quotient, sizeof(quotient) / sizeof(DWORD))) {
remainder = VARIANT_int_divbychar(quotient, sizeof(quotient) / sizeof(DWORD), 10);
while (!overflow && !VARIANT_int_iszero(quotient, ARRAY_SIZE(quotient))) {
remainder = VARIANT_int_divbychar(quotient, ARRAY_SIZE(quotient), 10);
if (i + 2 > n) {
overflow = TRUE;
} else {
@ -4859,7 +4857,7 @@ static BOOL VARIANT_DI_tostringW(const VARIANT_DI * a, WCHAR * s, unsigned int n
}
}
if (!overflow && !VARIANT_int_iszero(a->bitsnum, sizeof(a->bitsnum) / sizeof(DWORD))) {
if (!overflow && !VARIANT_int_iszero(a->bitsnum, ARRAY_SIZE(a->bitsnum))) {
/* reverse order of digits */
WCHAR * x = s; WCHAR * y = s + i - 1;
@ -5175,10 +5173,10 @@ static HRESULT VARIANT_DI_div(const VARIANT_DI * dividend, const VARIANT_DI * di
{
HRESULT r_overflow = S_OK;
if (VARIANT_int_iszero(divisor->bitsnum, sizeof(divisor->bitsnum)/sizeof(DWORD))) {
if (VARIANT_int_iszero(divisor->bitsnum, ARRAY_SIZE(divisor->bitsnum))) {
/* division by 0 */
r_overflow = DISP_E_DIVBYZERO;
} else if (VARIANT_int_iszero(dividend->bitsnum, sizeof(dividend->bitsnum)/sizeof(DWORD))) {
} else if (VARIANT_int_iszero(dividend->bitsnum, ARRAY_SIZE(dividend->bitsnum))) {
VARIANT_DI_clear(quotient);
} else {
int quotientscale, remainderscale, tempquotientscale;
@ -5208,17 +5206,14 @@ static HRESULT VARIANT_DI_div(const VARIANT_DI * dividend, const VARIANT_DI * di
memset(remainderplusquotient, 0, sizeof(remainderplusquotient));
memcpy(remainderplusquotient, dividend->bitsnum, sizeof(dividend->bitsnum));
do {
VARIANT_int_div(
remainderplusquotient, 4,
divisor->bitsnum, sizeof(divisor->bitsnum)/sizeof(DWORD));
underflow = VARIANT_int_addlossy(
quotient->bitsnum, &quotientscale, sizeof(quotient->bitsnum) / sizeof(DWORD),
remainderplusquotient, &tempquotientscale, 4);
VARIANT_int_div(remainderplusquotient, 4, divisor->bitsnum, ARRAY_SIZE(divisor->bitsnum));
underflow = VARIANT_int_addlossy( quotient->bitsnum, &quotientscale,
ARRAY_SIZE(quotient->bitsnum), remainderplusquotient, &tempquotientscale, 4);
if (round_remainder) {
if(remainderplusquotient[4] >= 5){
unsigned int i;
unsigned char remainder = 1;
for (i = 0; i < sizeof(quotient->bitsnum) / sizeof(DWORD) && remainder; i++) {
for (i = 0; i < ARRAY_SIZE(quotient->bitsnum) && remainder; i++) {
ULONGLONG digit = quotient->bitsnum[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
quotient->bitsnum[i] = digit & 0xFFFFFFFF;
@ -5239,9 +5234,9 @@ static HRESULT VARIANT_DI_div(const VARIANT_DI * dividend, const VARIANT_DI * di
while (r_overflow == S_OK && quotientscale < 0) {
memset(remainderplusquotient, 0, sizeof(remainderplusquotient));
memcpy(remainderplusquotient, quotient->bitsnum, sizeof(quotient->bitsnum));
VARIANT_int_mulbychar(remainderplusquotient, sizeof(remainderplusquotient)/sizeof(DWORD), 10);
if (VARIANT_int_iszero(remainderplusquotient + sizeof(quotient->bitsnum)/sizeof(DWORD),
(sizeof(remainderplusquotient) - sizeof(quotient->bitsnum))/sizeof(DWORD))) {
VARIANT_int_mulbychar(remainderplusquotient, ARRAY_SIZE(remainderplusquotient), 10);
if (VARIANT_int_iszero(remainderplusquotient + ARRAY_SIZE(quotient->bitsnum),
ARRAY_SIZE(remainderplusquotient) - ARRAY_SIZE(quotient->bitsnum))) {
quotientscale++;
memcpy(quotient->bitsnum, remainderplusquotient, sizeof(quotient->bitsnum));
} else r_overflow = DISP_E_OVERFLOW;
@ -5562,9 +5557,9 @@ static HRESULT VARIANT_do_division(const DECIMAL *pDecLeft, const DECIMAL *pDecR
WARN("result scale is %u, scaling (with loss of significant digits)...\n",
di_result.scale);
while (di_result.scale > DEC_MAX_SCALE &&
!VARIANT_int_iszero(di_result.bitsnum, sizeof(di_result.bitsnum) / sizeof(DWORD)))
!VARIANT_int_iszero(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum)))
{
remainder = VARIANT_int_divbychar(di_result.bitsnum, sizeof(di_result.bitsnum) / sizeof(DWORD), 10);
remainder = VARIANT_int_divbychar(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum), 10);
di_result.scale--;
}
if (di_result.scale > DEC_MAX_SCALE)
@ -5576,7 +5571,7 @@ static HRESULT VARIANT_do_division(const DECIMAL *pDecLeft, const DECIMAL *pDecR
else if (remainder >= 5) /* round up result - native oleaut32 does this */
{
unsigned int i;
for (remainder = 1, i = 0; i < sizeof(di_result.bitsnum) / sizeof(DWORD) && remainder; i++) {
for (remainder = 1, i = 0; i < ARRAY_SIZE(di_result.bitsnum) && remainder; i++) {
ULONGLONG digit = di_result.bitsnum[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
di_result.bitsnum[i] = digit & 0xFFFFFFFF;
@ -5648,9 +5643,9 @@ HRESULT WINAPI VarDecMul(const DECIMAL* pDecLeft, const DECIMAL* pDecRight, DECI
WARN("result scale is %u, scaling (with loss of significant digits)...\n",
di_result.scale);
while (di_result.scale > DEC_MAX_SCALE &&
!VARIANT_int_iszero(di_result.bitsnum, sizeof(di_result.bitsnum)/sizeof(DWORD)))
!VARIANT_int_iszero(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum)))
{
VARIANT_int_divbychar(di_result.bitsnum, sizeof(di_result.bitsnum)/sizeof(DWORD), 10);
VARIANT_int_divbychar(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum), 10);
di_result.scale--;
}
if (di_result.scale > DEC_MAX_SCALE)
@ -6357,9 +6352,8 @@ static BSTR VARIANT_MakeBstr(LCID lcid, DWORD dwFlags, WCHAR *szOut)
{
/* Format the number for the locale */
szConverted[0] = '\0';
GetNumberFormatW(lcid,
dwFlags & LOCALE_NOUSEROVERRIDE,
szOut, NULL, szConverted, sizeof(szConverted)/sizeof(WCHAR));
GetNumberFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
szOut, NULL, szConverted, ARRAY_SIZE(szConverted));
szOut = szConverted;
}
return SysAllocStringByteLen((LPCSTR)szOut, strlenW(szOut) * sizeof(WCHAR));
@ -6368,7 +6362,7 @@ static BSTR VARIANT_MakeBstr(LCID lcid, DWORD dwFlags, WCHAR *szOut)
/* Create a (possibly localised) BSTR from a UI8 and sign */
static HRESULT VARIANT_BstrFromUInt(ULONG64 ulVal, LCID lcid, DWORD dwFlags, BSTR *pbstrOut)
{
WCHAR szBuff[64], *szOut = szBuff + sizeof(szBuff)/sizeof(WCHAR) - 1;
WCHAR szBuff[64], *szOut = szBuff + ARRAY_SIZE(szBuff) - 1;
if (!pbstrOut)
return E_INVALIDARG;
@ -6472,7 +6466,7 @@ static BSTR VARIANT_BstrReplaceDecimal(const WCHAR * buff, LCID lcid, ULONG dwFl
appropriate NUMBERFMTW structure to do the job via GetNumberFormatW().
*/
GetLocaleInfoW(lcid, LOCALE_SDECIMAL | (dwFlags & LOCALE_NOUSEROVERRIDE),
lpDecimalSep, sizeof(lpDecimalSep) / sizeof(WCHAR));
lpDecimalSep, ARRAY_SIZE(lpDecimalSep));
if (lpDecimalSep[0] == '.' && lpDecimalSep[1] == '\0')
{
/* locale is compatible with English - return original string */
@ -6497,7 +6491,7 @@ static BSTR VARIANT_BstrReplaceDecimal(const WCHAR * buff, LCID lcid, ULONG dwFl
if (p) minFormat.NumDigits = strlenW(p + 1);
numbuff[0] = '\0';
if (!GetNumberFormatW(lcid, 0, buff, &minFormat, numbuff, sizeof(numbuff) / sizeof(WCHAR)))
if (!GetNumberFormatW(lcid, 0, buff, &minFormat, numbuff, ARRAY_SIZE(numbuff)))
{
WARN("GetNumberFormatW() failed, returning raw number string instead\n");
bstrOut = SysAllocString(buff);
@ -6541,7 +6535,7 @@ static HRESULT VARIANT_BstrFromReal(DOUBLE dblIn, LCID lcid, ULONG dwFlags,
/* Format the number for the locale */
numbuff[0] = '\0';
GetNumberFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
buff, NULL, numbuff, sizeof(numbuff) / sizeof(WCHAR));
buff, NULL, numbuff, ARRAY_SIZE(numbuff));
TRACE("created NLS string %s\n", debugstr_w(numbuff));
*pbstrOut = SysAllocString(numbuff);
}
@ -6632,7 +6626,7 @@ HRESULT WINAPI VarBstrFromCy(CY cyIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut)
VARIANT_int_add(decVal.bitsnum, 3, &one, 1);
}
decVal.bitsnum[2] = 0;
VARIANT_DI_tostringW(&decVal, buff, sizeof(buff)/sizeof(buff[0]));
VARIANT_DI_tostringW(&decVal, buff, ARRAY_SIZE(buff));
if (dwFlags & LOCALE_USE_NLS)
{
@ -6641,7 +6635,7 @@ HRESULT WINAPI VarBstrFromCy(CY cyIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut)
/* Format the currency for the locale */
cybuff[0] = '\0';
GetCurrencyFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
buff, NULL, cybuff, sizeof(cybuff) / sizeof(WCHAR));
buff, NULL, cybuff, ARRAY_SIZE(cybuff));
*pbstrOut = SysAllocString(cybuff);
}
else
@ -6814,8 +6808,8 @@ HRESULT WINAPI VarBstrFromDate(DATE dateIn, LCID lcid, ULONG dwFlags, BSTR* pbst
if (dwFlags & VAR_TIMEVALUEONLY)
date[0] = '\0';
else
if (!GetLocaleInfoW(lcid, LOCALE_SSHORTDATE, fmt_buff, sizeof(fmt_buff)/sizeof(WCHAR)) ||
!get_date_format(lcid, dwFlags, &st, fmt_buff, date, sizeof(date)/sizeof(WCHAR)))
if (!GetLocaleInfoW(lcid, LOCALE_SSHORTDATE, fmt_buff, ARRAY_SIZE(fmt_buff)) ||
!get_date_format(lcid, dwFlags, &st, fmt_buff, date, ARRAY_SIZE(date)))
return E_INVALIDARG;
if (!(dwFlags & VAR_DATEVALUEONLY))
@ -6823,8 +6817,7 @@ HRESULT WINAPI VarBstrFromDate(DATE dateIn, LCID lcid, ULONG dwFlags, BSTR* pbst
time = date + strlenW(date);
if (time != date)
*time++ = ' ';
if (!GetTimeFormatW(lcid, dwFormatFlags, &st, NULL, time,
sizeof(date)/sizeof(WCHAR)-(time-date)))
if (!GetTimeFormatW(lcid, dwFormatFlags, &st, NULL, time, ARRAY_SIZE(date)-(time-date)))
return E_INVALIDARG;
}
@ -7012,7 +7005,7 @@ HRESULT WINAPI VarBstrFromDec(DECIMAL* pDecIn, LCID lcid, ULONG dwFlags, BSTR* p
/* Format the number for the locale */
numbuff[0] = '\0';
GetNumberFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
buff, NULL, numbuff, sizeof(numbuff) / sizeof(WCHAR));
buff, NULL, numbuff, ARRAY_SIZE(numbuff));
TRACE("created NLS string %s\n", debugstr_w(numbuff));
*pbstrOut = SysAllocString(numbuff);
}
@ -7625,7 +7618,7 @@ HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pd
1,2,3,4,5,6,7,8,9,10,11,12,13
};
unsigned int i;
BSTR tokens[sizeof(ParseDateTokens)/sizeof(ParseDateTokens[0])];
BSTR tokens[ARRAY_SIZE(ParseDateTokens)];
DATEPARSE dp;
DWORD dwDateSeps = 0, iDate = 0;
HRESULT hRet = S_OK;
@ -7648,7 +7641,7 @@ HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pd
TRACE("iDate is %d\n", iDate);
/* Get the month/day/am/pm tokens for this locale */
for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
for (i = 0; i < ARRAY_SIZE(tokens); i++)
{
WCHAR buff[128];
LCTYPE lctype = ParseDateTokens[i] | (dwFlags & LOCALE_NOUSEROVERRIDE);
@ -7657,7 +7650,7 @@ HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pd
* GetAltMonthNames(). We should really cache these strings too.
*/
buff[0] = '\0';
GetLocaleInfoW(lcid, lctype, buff, sizeof(buff)/sizeof(WCHAR));
GetLocaleInfoW(lcid, lctype, buff, ARRAY_SIZE(buff));
tokens[i] = SysAllocString(buff);
TRACE("token %d is %s\n", i, debugstr_w(tokens[i]));
}
@ -7680,7 +7673,7 @@ HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pd
{
BOOL bFound = FALSE;
for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
for (i = 0; i < ARRAY_SIZE(tokens); i++)
{
DWORD dwLen = strlenW(tokens[i]);
if (dwLen && !strncmpiW(strIn, tokens[i], dwLen))
@ -7940,7 +7933,7 @@ HRESULT WINAPI VarDateFromStr(OLECHAR* strIn, LCID lcid, ULONG dwFlags, DATE* pd
}
}
for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
for (i = 0; i < ARRAY_SIZE(tokens); i++)
SysFreeString(tokens[i]);
return hRet;
}