Author: hbelusca Date: Sun Dec 4 18:28:33 2016 New Revision: 73425
URL: http://svn.reactos.org/svn/reactos?rev=73425&view=rev Log: [USERENV]: Use ARRAYSIZE instead of hardcoding the sizes of the static buffers.
Modified: trunk/reactos/dll/win32/userenv/profile.c trunk/reactos/dll/win32/userenv/setup.c
Modified: trunk/reactos/dll/win32/userenv/profile.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/profile.c... ============================================================================== --- trunk/reactos/dll/win32/userenv/profile.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/userenv/profile.c [iso-8859-1] Sun Dec 4 18:28:33 2016 @@ -44,7 +44,7 @@ /* Build profile name postfix */ if (!ExpandEnvironmentStringsW(L"%SystemRoot%", szSystemRoot, - MAX_PATH)) + ARRAYSIZE(szSystemRoot))) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; @@ -180,7 +180,7 @@ }
/* Get profiles path */ - dwLength = MAX_PATH * sizeof(WCHAR); + dwLength = sizeof(szRawProfilesPath); Error = RegQueryValueExW(hKey, L"ProfilesDirectory", NULL, @@ -198,7 +198,7 @@ /* Expand it */ if (!ExpandEnvironmentStringsW(szRawProfilesPath, szProfilesPath, - MAX_PATH)) + ARRAYSIZE(szProfilesPath))) { DPRINT1("Error: %lu\n", GetLastError()); RegCloseKey(hKey); @@ -216,7 +216,7 @@ }
/* Get default user path */ - dwLength = MAX_PATH * sizeof(WCHAR); + dwLength = sizeof(szBuffer); Error = RegQueryValueExW(hKey, L"DefaultUserProfile", NULL, @@ -318,7 +318,7 @@ 0, REG_EXPAND_SZ, (LPBYTE)szBuffer, - (wcslen (szBuffer) + 1) * sizeof(WCHAR)); + (wcslen(szBuffer) + 1) * sizeof(WCHAR)); if (Error != ERROR_SUCCESS) { DPRINT1("Error: %lu\n", Error); @@ -766,13 +766,13 @@ /* Expand it */ if (!ExpandEnvironmentStringsW(szBuffer, szProfilesPath, - MAX_PATH)) + ARRAYSIZE(szProfilesPath))) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; }
- dwLength = wcslen (szProfilesPath) + 1; + dwLength = wcslen(szProfilesPath) + 1; if (lpProfilesDir != NULL) { if (*lpcchSize < dwLength) @@ -915,7 +915,7 @@ /* Expand it */ if (!ExpandEnvironmentStringsW(szRawImagePath, szImagePath, - MAX_PATH)) + ARRAYSIZE(szImagePath))) { DPRINT1 ("Error: %lu\n", GetLastError()); return FALSE; @@ -995,7 +995,7 @@ }
/* Convert the structure to UNICODE... */ - ProfileInfoW.dwSize = sizeof(PROFILEINFOW); + ProfileInfoW.dwSize = sizeof(ProfileInfoW); ProfileInfoW.dwFlags = lpProfileInfo->dwFlags;
if (lpProfileInfo->lpUserName)
Modified: trunk/reactos/dll/win32/userenv/setup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/setup.c?r... ============================================================================== --- trunk/reactos/dll/win32/userenv/setup.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/userenv/setup.c [iso-8859-1] Sun Dec 4 18:28:33 2016 @@ -122,7 +122,7 @@ if (!LoadStringW(hInstance, IDS_PROFILEPATH, szBuffer, - MAX_PATH)) + ARRAYSIZE(szBuffer))) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; @@ -143,7 +143,7 @@ /* Expand it */ if (!ExpandEnvironmentStringsW(szBuffer, szProfilesPath, - MAX_PATH)) + ARRAYSIZE(szProfilesPath))) { DPRINT1("Error: %lu\n", GetLastError()); RegCloseKey(hKey); @@ -162,7 +162,7 @@ }
/* Store the profiles directory path in the registry */ - dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); + dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); Error = RegSetValueExW(hKey, L"ProfilesDirectory", 0, @@ -186,7 +186,7 @@ wcscat(szProfilePath, szBuffer);
/* Attempt default user directory creation */ - if (!CreateDirectoryW (szProfilePath, NULL)) + if (!CreateDirectoryW(szProfilePath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { @@ -196,7 +196,7 @@ }
/* Directory existed, let's try to append the postfix */ - if (!AppendSystemPostfix(szBuffer, MAX_PATH)) + if (!AppendSystemPostfix(szBuffer, ARRAYSIZE(szBuffer))) { DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); RegCloseKey(hKey); @@ -221,7 +221,7 @@ }
/* Store the default user profile path in the registry */ - dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); + dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); Error = RegSetValueExW(hKey, L"DefaultUserProfile", 0, @@ -254,7 +254,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath); @@ -304,7 +304,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath); @@ -330,7 +330,7 @@ }
/* Set 'Fonts' folder path */ - GetWindowsDirectoryW(szBuffer, MAX_PATH); + GetWindowsDirectoryW(szBuffer, ARRAYSIZE(szBuffer)); wcscat(szBuffer, L"\Fonts");
dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); @@ -375,7 +375,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath); @@ -411,7 +411,7 @@ wcscat(szProfilePath, szBuffer);
/* Attempt 'All Users' directory creation */ - if (!CreateDirectoryW (szProfilePath, NULL)) + if (!CreateDirectoryW(szProfilePath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { @@ -420,7 +420,7 @@ }
/* Directory existed, let's try to append the postfix */ - if (!AppendSystemPostfix(szBuffer, MAX_PATH)) + if (!AppendSystemPostfix(szBuffer, ARRAYSIZE(szBuffer))) { DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); return FALSE; @@ -486,7 +486,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath); @@ -536,7 +536,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath); @@ -588,7 +588,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath); @@ -619,7 +619,7 @@ if (!LoadStringW(hInstance, IDS_PROGRAMFILES, szBuffer, - MAX_PATH)) + ARRAYSIZE(szBuffer))) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; @@ -628,7 +628,7 @@ if (!LoadStringW(hInstance, IDS_COMMONFILES, szCommonFilesDirPath, - MAX_PATH)) + ARRAYSIZE(szCommonFilesDirPath))) { DPRINT1("Warning: %lu\n", GetLastError()); } @@ -636,7 +636,7 @@ /* Expand it */ if (!ExpandEnvironmentStringsW(szBuffer, szProfilesPath, - MAX_PATH)) + ARRAYSIZE(szProfilesPath))) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; @@ -647,8 +647,8 @@ wcscat(szBuffer, szCommonFilesDirPath);
if (!ExpandEnvironmentStringsW(szBuffer, - szCommonFilesDirPath, - MAX_PATH)) + szCommonFilesDirPath, + ARRAYSIZE(szCommonFilesDirPath))) { DPRINT1("Warning: %lu\n", GetLastError()); } @@ -666,7 +666,7 @@ return FALSE; }
- dwLength = (wcslen (szProfilesPath) + 1) * sizeof(WCHAR); + dwLength = (wcslen(szProfilesPath) + 1) * sizeof(WCHAR); Error = RegSetValueExW(hKey, L"ProgramFilesDir", 0, @@ -693,12 +693,12 @@ DPRINT1("Warning: %lu\n", Error); }
- RegCloseKey (hKey); + RegCloseKey(hKey);
/* Create directory */ if (!CreateDirectoryW(szProfilesPath, NULL)) { - if (GetLastError () != ERROR_ALREADY_EXISTS) + if (GetLastError() != ERROR_ALREADY_EXISTS) { DPRINT1("Error: %lu\n", GetLastError()); return FALSE; @@ -708,7 +708,7 @@ /* Create directory */ if (!CreateDirectoryW(szCommonFilesDirPath, NULL)) { - if (GetLastError () != ERROR_ALREADY_EXISTS) + if (GetLastError() != ERROR_ALREADY_EXISTS) { DPRINT1("Warning: %lu\n", GetLastError()); } @@ -759,7 +759,7 @@ if (!LoadStringW(hInstance, lpFolderData->uId, &szBuffer[dwLength], - MAX_PATH - dwLength)) + ARRAYSIZE(szBuffer) - dwLength)) { /* Use the default name instead */ wcscat(szBuffer, lpFolderData->lpPath);