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

wininet: Use the ARRAY_SIZE() macro.

parent 717a17b2
......@@ -151,18 +151,18 @@ static WCHAR *create_cookie_url(substr_t domain, substr_t path, substr_t *ret_pa
static const WCHAR cookie_prefix[] = {'C','o','o','k','i','e',':'};
user_len = sizeof(user)/sizeof(WCHAR);
user_len = ARRAY_SIZE(user);
if(!GetUserNameW(user, &user_len))
return FALSE;
user_len--;
len = sizeof(cookie_prefix)/sizeof(WCHAR) + user_len + 1 /* @ */ + domain.len + path.len;
len = ARRAY_SIZE(cookie_prefix) + user_len + 1 /* @ */ + domain.len + path.len;
url = heap_alloc((len+1) * sizeof(WCHAR));
if(!url)
return NULL;
memcpy(url, cookie_prefix, sizeof(cookie_prefix));
p = url + sizeof(cookie_prefix)/sizeof(WCHAR);
p = url + ARRAY_SIZE(cookie_prefix);
memcpy(p, user, user_len*sizeof(WCHAR));
p += user_len;
......@@ -658,7 +658,7 @@ DWORD get_cookie_header(const WCHAR *host, const WCHAR *path, WCHAR **ret)
ptr = header = heap_alloc(sizeof(cookieW) + (cookie_set.string_len + 3 /* crlf0 */) * sizeof(WCHAR));
if(header) {
memcpy(ptr, cookieW, sizeof(cookieW));
ptr += sizeof(cookieW)/sizeof(*cookieW);
ptr += ARRAY_SIZE(cookieW);
cookie_set_to_string(&cookie_set, ptr);
heap_free(cookie_set.cookies);
......@@ -949,7 +949,7 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D
if(!(end_ptr = memchrW(data.str, ';', data.len)))
end_ptr = data.str + data.len;
if(data.len >= (len = sizeof(szDomain)/sizeof(WCHAR)) && !strncmpiW(data.str, szDomain, len)) {
if(data.len >= (len = ARRAY_SIZE(szDomain)) && !strncmpiW(data.str, szDomain, len)) {
substr_skip(&data, len);
if(data.len && *data.str == '.')
......@@ -960,17 +960,17 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D
domain = substr(data.str, end_ptr-data.str);
TRACE("Parsing new domain %s\n", debugstr_wn(domain.str, domain.len));
}else if(data.len >= (len = sizeof(szPath)/sizeof(WCHAR)) && !strncmpiW(data.str, szPath, len)) {
}else if(data.len >= (len = ARRAY_SIZE(szPath)) && !strncmpiW(data.str, szPath, len)) {
substr_skip(&data, len);
path = substr(data.str, end_ptr - data.str);
TRACE("Parsing new path %s\n", debugstr_wn(path.str, path.len));
}else if(data.len >= (len = sizeof(szExpires)/sizeof(WCHAR)) && !strncmpiW(data.str, szExpires, len)) {
}else if(data.len >= (len = ARRAY_SIZE(szExpires)) && !strncmpiW(data.str, szExpires, len)) {
SYSTEMTIME st;
WCHAR buf[128];
substr_skip(&data, len);
if(end_ptr - data.str < sizeof(buf)/sizeof(WCHAR)-1) {
if(end_ptr - data.str < ARRAY_SIZE(buf)-1) {
memcpy(buf, data.str, data.len*sizeof(WCHAR));
buf[data.len] = 0;
......@@ -983,10 +983,10 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D
}
}
}
}else if(data.len >= (len = sizeof(szSecure)/sizeof(WCHAR)) && !strncmpiW(data.str, szSecure, len)) {
}else if(data.len >= (len = ARRAY_SIZE(szSecure)) && !strncmpiW(data.str, szSecure, len)) {
substr_skip(&data, len);
FIXME("secure not handled\n");
}else if(data.len >= (len = sizeof(szHttpOnly)/sizeof(WCHAR)) && !strncmpiW(data.str, szHttpOnly, len)) {
}else if(data.len >= (len = ARRAY_SIZE(szHttpOnly)) && !strncmpiW(data.str, szHttpOnly, len)) {
substr_skip(&data, len);
if(!(flags & INTERNET_COOKIE_HTTPONLY)) {
......@@ -996,11 +996,11 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D
}
cookie_flags |= INTERNET_COOKIE_HTTPONLY;
}else if(data.len >= (len = sizeof(szVersion)/sizeof(WCHAR)) && !strncmpiW(data.str, szVersion, len)) {
}else if(data.len >= (len = ARRAY_SIZE(szVersion)) && !strncmpiW(data.str, szVersion, len)) {
substr_skip(&data, len);
FIXME("version not handled (%s)\n",debugstr_wn(data.str, data.len));
}else if(data.len >= (len = sizeof(max_ageW)/sizeof(WCHAR)) && !strncmpiW(data.str, max_ageW, len)) {
}else if(data.len >= (len = ARRAY_SIZE(max_ageW)) && !strncmpiW(data.str, max_ageW, len)) {
/* Native doesn't support Max-Age attribute. */
WARN("Max-Age ignored\n");
}else if(data.len) {
......
......@@ -135,12 +135,10 @@ static BOOL WININET_GetSetPassword( HWND hdlg, LPCWSTR szServer,
if( bSet )
{
szUserPass[0] = 0;
GetWindowTextW( hUserItem, szUserPass,
(sizeof szUserPass-1)/sizeof(WCHAR) );
GetWindowTextW( hUserItem, szUserPass, ARRAY_SIZE( szUserPass ) - 1 );
lstrcatW(szUserPass, szColon);
u_len = strlenW( szUserPass );
GetWindowTextW( hPassItem, szUserPass+u_len,
(sizeof szUserPass)/sizeof(WCHAR)-u_len );
GetWindowTextW( hPassItem, szUserPass+u_len, ARRAY_SIZE( szUserPass ) - u_len );
r_len = (strlenW( szResource ) + 1)*sizeof(WCHAR);
u_len = (strlenW( szUserPass ) + 1)*sizeof(WCHAR);
......@@ -230,7 +228,7 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog(
/* extract the Realm from the proxy response and show it */
if( WININET_GetAuthRealm( params->req->hdr.hInternet,
szRealm, sizeof szRealm/sizeof(WCHAR), TRUE ) )
szRealm, ARRAY_SIZE( szRealm ), TRUE ) )
{
hitem = GetDlgItem( hdlg, IDC_REALM );
SetWindowTextW( hitem, szRealm );
......@@ -257,18 +255,18 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog(
username[0] = 0;
hitem = GetDlgItem( hdlg, IDC_USERNAME );
if( hitem )
GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) );
GetWindowTextW( hitem, username, ARRAY_SIZE( username ));
password[0] = 0;
hitem = GetDlgItem( hdlg, IDC_PASSWORD );
if( hitem )
GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) );
GetWindowTextW( hitem, password, ARRAY_SIZE( password ));
hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD );
if( hitem &&
SendMessageW( hitem, BM_GETSTATE, 0, 0 ) &&
WININET_GetAuthRealm( params->req->hdr.hInternet,
szRealm, sizeof szRealm/sizeof(WCHAR), TRUE) )
szRealm, ARRAY_SIZE( szRealm ), TRUE) )
WININET_GetSetPassword( hdlg, params->req->session->appInfo->proxy, szRealm, TRUE );
WININET_SetAuthorization( params->req, username, password, TRUE );
......@@ -305,7 +303,7 @@ static INT_PTR WINAPI WININET_PasswordDialog(
/* extract the Realm from the response and show it */
if( WININET_GetAuthRealm( params->req->hdr.hInternet,
szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ) )
szRealm, ARRAY_SIZE( szRealm ), FALSE ) )
{
hitem = GetDlgItem( hdlg, IDC_REALM );
SetWindowTextW( hitem, szRealm );
......@@ -332,18 +330,18 @@ static INT_PTR WINAPI WININET_PasswordDialog(
username[0] = 0;
hitem = GetDlgItem( hdlg, IDC_USERNAME );
if( hitem )
GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) );
GetWindowTextW( hitem, username, ARRAY_SIZE( username ));
password[0] = 0;
hitem = GetDlgItem( hdlg, IDC_PASSWORD );
if( hitem )
GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) );
GetWindowTextW( hitem, password, ARRAY_SIZE( password ));
hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD );
if( hitem &&
SendMessageW( hitem, BM_GETSTATE, 0, 0 ) &&
WININET_GetAuthRealm( params->req->hdr.hInternet,
szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ))
szRealm, ARRAY_SIZE( szRealm ), FALSE ))
{
WININET_GetSetPassword( hdlg, params->req->session->hostName, szRealm, TRUE );
}
......
......@@ -1712,7 +1712,7 @@ static BOOL HTTP_DomainMatches(LPCWSTR server, substr_t domain)
const WCHAR *dot, *ptr;
int len;
if(domain.len == sizeof(localW)/sizeof(WCHAR)-1 && !strncmpiW(domain.str, localW, domain.len) && !strchrW(server, '.' ))
if(domain.len == ARRAY_SIZE(localW)-1 && !strncmpiW(domain.str, localW, domain.len) && !strchrW(server, '.' ))
return TRUE;
if(domain.len && *domain.str != '*')
......@@ -2409,8 +2409,8 @@ static void create_cache_entry(http_request_t *req)
if(!end)
end = ptr + strlenW(ptr);
if(!strncmpiW(ptr, no_cacheW, sizeof(no_cacheW)/sizeof(*no_cacheW)-1)
|| !strncmpiW(ptr, no_storeW, sizeof(no_storeW)/sizeof(*no_storeW)-1)) {
if(!strncmpiW(ptr, no_cacheW, ARRAY_SIZE(no_cacheW)-1)
|| !strncmpiW(ptr, no_storeW, ARRAY_SIZE(no_storeW)-1)) {
b = FALSE;
break;
}
......@@ -3871,18 +3871,18 @@ BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel,
TRACE("(%p, 0x%08x)--> %d\n", hHttpRequest, dwInfoLevel, info);
TRACE(" Attribute:");
for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) {
for (i = 0; i < ARRAY_SIZE(query_flags); i++) {
if (query_flags[i].val == info) {
TRACE(" %s", query_flags[i].name);
break;
}
}
if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) {
if (i == ARRAY_SIZE(query_flags)) {
TRACE(" Unknown (%08x)", info);
}
TRACE(" Modifier:");
for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) {
for (i = 0; i < ARRAY_SIZE(modifier_flags); i++) {
if (modifier_flags[i].val & info_mod) {
TRACE(" %s", modifier_flags[i].name);
info_mod &= ~ modifier_flags[i].val;
......@@ -4208,7 +4208,7 @@ static WORD HTTP_ParseWkday(LPCWSTR day)
{ 'f','r','i',0 },
{ 's','a','t',0 }};
unsigned int i;
for (i = 0; i < sizeof(days)/sizeof(*days); i++)
for (i = 0; i < ARRAY_SIZE(days); i++)
if (!strcmpiW(day, days[i]))
return i;
......@@ -4313,7 +4313,7 @@ static BOOL HTTP_ParseDateAsAsctime(LPCWSTR value, FILETIME *ft)
unsigned long num;
for (ptr = value, dayPtr = day; *ptr && !isspaceW(*ptr) &&
dayPtr - day < sizeof(day) / sizeof(day[0]) - 1; ptr++, dayPtr++)
dayPtr - day < ARRAY_SIZE(day) - 1; ptr++, dayPtr++)
*dayPtr = *ptr;
*dayPtr = 0;
st.wDayOfWeek = HTTP_ParseWkday(day);
......@@ -4326,8 +4326,7 @@ static BOOL HTTP_ParseDateAsAsctime(LPCWSTR value, FILETIME *ft)
while (isspaceW(*ptr))
ptr++;
for (monthPtr = month; !isspaceW(*ptr) &&
monthPtr - month < sizeof(month) / sizeof(month[0]) - 1;
for (monthPtr = month; !isspaceW(*ptr) && monthPtr - month < ARRAY_SIZE(month) - 1;
monthPtr++, ptr++)
*monthPtr = *ptr;
*monthPtr = 0;
......@@ -4423,8 +4422,7 @@ static BOOL HTTP_ParseRfc1123Date(LPCWSTR value, FILETIME *ft)
while (isspaceW(*ptr))
ptr++;
for (monthPtr = month; !isspaceW(*ptr) &&
monthPtr - month < sizeof(month) / sizeof(month[0]) - 1;
for (monthPtr = month; !isspaceW(*ptr) && monthPtr - month < ARRAY_SIZE(month) - 1;
monthPtr++, ptr++)
*monthPtr = *ptr;
*monthPtr = 0;
......@@ -4471,7 +4469,7 @@ static WORD HTTP_ParseWeekday(LPCWSTR day)
{ 'f','r','i','d','a','y',0 },
{ 's','a','t','u','r','d','a','y',0 }};
unsigned int i;
for (i = 0; i < sizeof(days)/sizeof(*days); i++)
for (i = 0; i < ARRAY_SIZE(days); i++)
if (!strcmpiW(day, days[i]))
return i;
......@@ -4501,7 +4499,7 @@ static BOOL HTTP_ParseRfc850Date(LPCWSTR value, FILETIME *ft)
return FALSE;
}
}
else if (ptr - value < sizeof(day) / sizeof(day[0]))
else if (ptr - value < ARRAY_SIZE(day))
{
memcpy(day, value, (ptr - value) * sizeof(WCHAR));
day[ptr - value + 1] = 0;
......@@ -4538,8 +4536,7 @@ static BOOL HTTP_ParseRfc850Date(LPCWSTR value, FILETIME *ft)
}
ptr++;
for (monthPtr = month; *ptr != '-' &&
monthPtr - month < sizeof(month) / sizeof(month[0]) - 1;
for (monthPtr = month; *ptr != '-' && monthPtr - month < ARRAY_SIZE(month) - 1;
monthPtr++, ptr++)
*monthPtr = *ptr;
*monthPtr = 0;
......@@ -4827,7 +4824,7 @@ static void set_content_length_header( http_request_t *request, DWORD len, DWORD
{
static const WCHAR fmtW[] =
{'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','u','\r','\n',0};
WCHAR buf[sizeof(fmtW)/sizeof(fmtW[0]) + 10];
WCHAR buf[ARRAY_SIZE(fmtW) + 10];
sprintfW( buf, fmtW, len );
HTTP_HttpAddRequestHeadersW( request, buf, ~0u, flags );
......
......@@ -777,7 +777,7 @@ static void dump_INTERNET_FLAGS(DWORD dwFlags)
#undef FE
unsigned int i;
for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
for (i = 0; i < ARRAY_SIZE(flag); i++) {
if (flag[i].val & dwFlags) {
TRACE(" %s", flag[i].name);
dwFlags &= ~flag[i].val;
......@@ -1018,7 +1018,7 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
for (i = 0; i < ARRAY_SIZE(access_type); i++) {
if (access_type[i].val == dwAccessType) {
access_type_str = access_type[i].name;
break;
......@@ -1623,7 +1623,7 @@ static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
if(lpszScheme==NULL)
return INTERNET_SCHEME_UNKNOWN;
for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
for (i = 0; i < ARRAY_SIZE(url_schemes); i++)
if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp))
return INTERNET_SCHEME_FIRST + i;
......@@ -4066,7 +4066,7 @@ static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
if (scheme < INTERNET_SCHEME_FIRST)
return NULL;
index = scheme - INTERNET_SCHEME_FIRST;
if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
if (index >= ARRAY_SIZE(url_schemes))
return NULL;
return (LPCWSTR)url_schemes[index];
}
......@@ -4343,7 +4343,7 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
{
memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
lpszUrl += ARRAY_SIZE(slashSlashW);
}
if (lpUrlComponents->lpszUserName)
......
......@@ -639,7 +639,7 @@ static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size)
{conn->ssl_sizes.cbTrailer, SECBUFFER_STREAM_TRAILER, conn->ssl_buf+conn->ssl_sizes.cbHeader+size},
{0, SECBUFFER_EMPTY, NULL}
};
SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
SecBufferDesc buf_desc = {SECBUFFER_VERSION, ARRAY_SIZE(bufs), bufs};
SECURITY_STATUS res;
memcpy(bufs[1].pvBuffer, msg, size);
......@@ -698,7 +698,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blo
{
const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer;
SecBuffer bufs[4];
SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
SecBufferDesc buf_desc = {SECBUFFER_VERSION, ARRAY_SIZE(bufs), bufs};
SSIZE_T size, buf_len = 0;
int i;
SECURITY_STATUS res;
......@@ -781,7 +781,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blo
}
} while(res != SEC_E_OK);
for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) {
for(i = 0; i < ARRAY_SIZE(bufs); i++) {
if(bufs[i].BufferType == SECBUFFER_DATA) {
size = min(buf_size, bufs[i].cbBuffer);
memcpy(buf, bufs[i].pvBuffer, size);
......@@ -798,7 +798,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blo
}
}
for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) {
for(i = 0; i < ARRAY_SIZE(bufs); i++) {
if(bufs[i].BufferType == SECBUFFER_EXTRA) {
conn->extra_buf = heap_alloc(bufs[i].cbBuffer);
if(!conn->extra_buf)
......
......@@ -766,7 +766,7 @@ static void cache_containers_init(void)
};
DWORD i;
for (i = 0; i < sizeof(DefaultContainerData) / sizeof(DefaultContainerData[0]); i++)
for (i = 0; i < ARRAY_SIZE(DefaultContainerData); i++)
{
WCHAR wszCachePath[MAX_PATH];
WCHAR wszMutexName[MAX_PATH];
......@@ -1478,12 +1478,12 @@ static DWORD urlcache_hash_key(LPCSTR lpszKey)
BYTE key[4];
DWORD i;
for (i = 0; i < sizeof(key) / sizeof(key[0]); i++)
for (i = 0; i < ARRAY_SIZE(key); i++)
key[i] = lookupTable[(*lpszKey + i) & 0xFF];
for (lpszKey++; *lpszKey; lpszKey++)
{
for (i = 0; i < sizeof(key) / sizeof(key[0]); i++)
for (i = 0; i < ARRAY_SIZE(key); i++)
key[i] = lookupTable[*lpszKey ^ key[i]];
}
......@@ -2441,7 +2441,7 @@ BOOL WINAPI FreeUrlCacheSpaceW(LPCWSTR cache_path, DWORD size, DWORD filter)
hash_table_entry = 0;
rate_no = 0;
GetSystemTimeAsFileTime(&cur_time);
while(rate_no<sizeof(rate)/sizeof(*rate) &&
while(rate_no < ARRAY_SIZE(rate) &&
urlcache_next_entry(header, &hash_table_off, &hash_table_entry, &hash_entry, &entry)) {
if(entry->signature != URL_SIGNATURE) {
WARN("only url entries are currently supported\n");
......
......@@ -214,7 +214,7 @@ static const char *get_callback_name(DWORD dwInternetStatus) {
};
DWORD i;
for (i = 0; i < (sizeof(internet_status) / sizeof(internet_status[0])); i++) {
for (i = 0; i < ARRAY_SIZE(internet_status); i++) {
if (internet_status[i].val == dwInternetStatus) return internet_status[i].name;
}
return "Unknown";
......
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