Commit af4821ca authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

msvcrt: Use the ARRAY_SIZE() macro.

parent 27c88fc4
......@@ -124,7 +124,7 @@ static BOOL handle_enhanced_keys(INPUT_RECORD *ir, unsigned char *ch1, unsigned
{
int i;
for (i = 0; i < sizeof(enh_map) / sizeof(enh_map[0]); i++)
for (i = 0; i < ARRAY_SIZE(enh_map); i++)
{
if (ir->Event.KeyEvent.wVirtualScanCode == enh_map[i].vk)
{
......
......@@ -493,7 +493,7 @@ unsigned short __cdecl wctype(const char *property)
};
unsigned int i;
for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
for(i=0; i<ARRAY_SIZE(properties); i++)
if(!strcmp(property, properties[i].name))
return properties[i].mask;
......
......@@ -123,7 +123,7 @@ char *MSVCRT__sys_errlist[] =
str_generic_error
};
unsigned int MSVCRT__sys_nerr = sizeof(MSVCRT__sys_errlist)/sizeof(MSVCRT__sys_errlist[0]) - 1;
unsigned int MSVCRT__sys_nerr = ARRAY_SIZE(MSVCRT__sys_errlist) - 1;
static MSVCRT_invalid_parameter_handler invalid_parameter_handler = NULL;
......
......@@ -136,8 +136,7 @@ static LONG msvcrt_exception_filter(struct _EXCEPTION_POINTERS *except)
int float_signal = MSVCRT__FPE_INVALID;
sighandlers[MSVCRT_SIGFPE] = MSVCRT_SIG_DFL;
for (i = 0; i < sizeof(float_exception_map) /
sizeof(float_exception_map[0]); i++)
for (i = 0; i < ARRAY_SIZE(float_exception_map); i++)
{
if (float_exception_map[i].status ==
except->ExceptionRecord->ExceptionCode)
......
......@@ -209,8 +209,7 @@ static void DoMessageBoxW(const MSVCRT_wchar_t *lead, const MSVCRT_wchar_t *mess
MSVCRT_wchar_t text[2048];
INT ret;
MSVCRT__snwprintf(text, sizeof(text)/sizeof(text[0]), message_format,
lead, MSVCRT__wpgmptr, message);
MSVCRT__snwprintf(text, ARRAY_SIZE(text), message_format, lead, MSVCRT__wpgmptr, message);
msgbox.cbSize = sizeof(msgbox);
msgbox.hwndOwner = GetActiveWindow();
......
......@@ -1223,7 +1223,7 @@ void msvcrt_free_io(void)
MSVCRT__flushall();
MSVCRT__fcloseall();
for(i=0; i<sizeof(MSVCRT___pioinfo)/sizeof(MSVCRT___pioinfo[0]); i++)
for(i=0; i<ARRAY_SIZE(MSVCRT___pioinfo); i++)
{
if(!MSVCRT___pioinfo[i])
continue;
......@@ -1246,7 +1246,7 @@ void msvcrt_free_io(void)
}
}
for(i=0; i<sizeof(MSVCRT_fstream)/sizeof(MSVCRT_fstream[0]); i++)
for(i=0; i<ARRAY_SIZE(MSVCRT_fstream); i++)
MSVCRT_free(MSVCRT_fstream[i]);
}
......@@ -1606,29 +1606,29 @@ static int msvcrt_get_flags(const MSVCRT_wchar_t* mode, int *open_flags, int* st
mode++;
while(*mode == ' ') mode++;
if(!MSVCRT_CHECK_PMT(!strncmpW(ccs, mode, sizeof(ccs)/sizeof(ccs[0]))))
if(!MSVCRT_CHECK_PMT(!strncmpW(ccs, mode, ARRAY_SIZE(ccs))))
return -1;
mode += sizeof(ccs)/sizeof(ccs[0]);
mode += ARRAY_SIZE(ccs);
while(*mode == ' ') mode++;
if(!MSVCRT_CHECK_PMT(*mode == '='))
return -1;
mode++;
while(*mode == ' ') mode++;
if(!strncmpiW(utf8, mode, sizeof(utf8)/sizeof(utf8[0])))
if(!strncmpiW(utf8, mode, ARRAY_SIZE(utf8)))
{
*open_flags |= MSVCRT__O_U8TEXT;
mode += sizeof(utf8)/sizeof(utf8[0]);
mode += ARRAY_SIZE(utf8);
}
else if(!strncmpiW(utf16le, mode, sizeof(utf16le)/sizeof(utf16le[0])))
else if(!strncmpiW(utf16le, mode, ARRAY_SIZE(utf16le)))
{
*open_flags |= MSVCRT__O_U16TEXT;
mode += sizeof(utf16le)/sizeof(utf16le[0]);
mode += ARRAY_SIZE(utf16le);
}
else if(!strncmpiW(unicode, mode, sizeof(unicode)/sizeof(unicode[0])))
else if(!strncmpiW(unicode, mode, ARRAY_SIZE(unicode)))
{
*open_flags |= MSVCRT__O_WTEXT;
mode += sizeof(unicode)/sizeof(unicode[0]);
mode += ARRAY_SIZE(unicode);
}
else
{
......
......@@ -94,7 +94,7 @@ static const char * const _country_synonyms[] =
static void remap_synonym(char *name)
{
unsigned int i;
for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 )
for (i = 0; i < ARRAY_SIZE(_country_synonyms); i += 2)
{
if (!strcasecmp(_country_synonyms[i],name))
{
......@@ -595,7 +595,7 @@ void* CDECL _Gettnames(void)
TRACE("\n");
for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++)
for(i=0; i<ARRAY_SIZE(cur->str.str); i++)
size += strlen(cur->str.str[i])+1;
ret = MSVCRT_malloc(size);
......@@ -604,7 +604,7 @@ void* CDECL _Gettnames(void)
memcpy(ret, cur, size);
size = 0;
for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++) {
for(i=0; i<ARRAY_SIZE(cur->str.str); i++) {
ret->str.str[i] = &ret->data[size];
size += strlen(&ret->data[size])+1;
}
......@@ -1605,7 +1605,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
size = sizeof(MSVCRT___lc_time_data);
lcid_tmp = lcid[MSVCRT_LC_TIME] ? lcid[MSVCRT_LC_TIME] : MAKELCID(LANG_ENGLISH, SORT_DEFAULT);
for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
for(i=0; i<ARRAY_SIZE(time_data); i++) {
if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW);
}else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) {
......@@ -1637,7 +1637,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
}
ret = 0;
for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
for(i=0; i<ARRAY_SIZE(time_data); i++) {
locinfo->lc_time_curr->str.str[i] = &locinfo->lc_time_curr->data[ret];
if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
memcpy(&locinfo->lc_time_curr->data[ret], cloc_short_date, sizeof(cloc_short_date));
......@@ -1653,7 +1653,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
&locinfo->lc_time_curr->data[ret], size-ret);
}
}
for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
for(i=0; i<ARRAY_SIZE(time_data); i++) {
locinfo->lc_time_curr->wstr.wstr[i] = (MSVCRT_wchar_t*)&locinfo->lc_time_curr->data[ret];
if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
memcpy(&locinfo->lc_time_curr->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW));
......
......@@ -518,7 +518,7 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
flags.PadZero = '0';
i = flags.Precision;
flags.Precision = 2*sizeof(void*);
FUNC_NAME(pf_integer_conv)(buf, sizeof(buf)/sizeof(APICHAR), &flags,
FUNC_NAME(pf_integer_conv)(buf, ARRAY_SIZE(buf), &flags,
(ULONG_PTR)pf_args(args_ctx, pos, VT_PTR, valist).get_ptr);
flags.PadZero = 0;
flags.Precision = i;
......@@ -549,7 +549,7 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
flags.Precision = flags.FieldLength - 2;
max_len = (flags.FieldLength>flags.Precision ? flags.FieldLength : flags.Precision) + 10;
if(max_len > sizeof(buf)/sizeof(APICHAR))
if(max_len > ARRAY_SIZE(buf))
tmp = HeapAlloc(GetProcessHeap(), 0, max_len);
if(!tmp)
return -1;
......
......@@ -345,7 +345,7 @@ static MSVCRT_wchar_t *msvcrt_get_comspec(void)
MSVCRT_wchar_t *ret;
unsigned int len;
if (!(len = GetEnvironmentVariableW(comspec, NULL, 0))) len = sizeof(cmd)/sizeof(MSVCRT_wchar_t);
if (!(len = GetEnvironmentVariableW(comspec, NULL, 0))) len = ARRAY_SIZE(cmd);
if ((ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t))))
{
if (!GetEnvironmentVariableW(comspec, ret, len)) strcpyW(ret, cmd);
......
......@@ -344,7 +344,7 @@ static void ExternalContextBase_dtor(ExternalContextBase *this)
int i;
/* TODO: move the allocator cache to scheduler so it can be reused */
for(i=0; i<sizeof(this->allocator_cache)/sizeof(this->allocator_cache[0]); i++) {
for(i=0; i<ARRAY_SIZE(this->allocator_cache); i++) {
for(cur = this->allocator_cache[i]; cur; cur=next) {
next = cur->free.next;
MSVCRT_operator_delete(cur);
......@@ -413,10 +413,10 @@ void * CDECL Concurrency_Alloc(MSVCRT_size_t size)
int i;
C_ASSERT(sizeof(union allocator_cache_entry) <= 1 << 4);
for(i=0; i<sizeof(context->allocator_cache)/sizeof(context->allocator_cache[0]); i++)
for(i=0; i<ARRAY_SIZE(context->allocator_cache); i++)
if (1 << (i+4) >= size) break;
if(i==sizeof(context->allocator_cache)/sizeof(context->allocator_cache[0])) {
if(i==ARRAY_SIZE(context->allocator_cache)) {
p = MSVCRT_operator_new(size);
p->alloc.bucket = -1;
}else if (context->allocator_cache[i]) {
......@@ -446,7 +446,7 @@ void CDECL Concurrency_Free(void* mem)
if (context->context.vtable != &MSVCRT_ExternalContextBase_vtable) {
MSVCRT_operator_delete(p);
}else {
if(bucket >= 0 && bucket < sizeof(context->allocator_cache)/sizeof(context->allocator_cache[0]) &&
if(bucket >= 0 && bucket < ARRAY_SIZE(context->allocator_cache) &&
(!context->allocator_cache[bucket] || context->allocator_cache[bucket]->free.depth < 20)) {
p->free.next = context->allocator_cache[bucket];
p->free.depth = p->free.next ? p->free.next->free.depth+1 : 0;
......
......@@ -2109,7 +2109,7 @@ static int wctoint(WCHAR c, int base)
0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
};
int i;
for (i = 0; i < sizeof(zeros)/sizeof(zeros[0]) && c >= zeros[i]; ++i) {
for (i = 0; i < ARRAY_SIZE(zeros) && c >= zeros[i]; ++i) {
if (zeros[i] <= c && c <= zeros[i] + 9) {
v = c - zeros[i];
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment