- Bugfix: As szBuf was not null-terminated after the _tcscpy, the Processor Name String could have been wrapped wrong (ie. when it contained more spaces after character 30)

- Use a consistent indentation in SetProcNameString

svn path=/trunk/; revision=27781
This commit is contained in:
Colin Finck 2007-07-22 19:31:29 +00:00
parent 108a7ce988
commit 3087c56ea1

View file

@ -5,7 +5,7 @@
* PURPOSE: General System Information
* COPYRIGHT: Copyright Thomas Weidenmueller <w3seek@reactos.org>
* Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
* Copyright 2006 Colin Finck <mail@colinfinck.de>
* Copyright 2006-2007 Colin Finck <mail@colinfinck.de>
*
*/
@ -118,83 +118,86 @@ SetProcNameString(HWND hwnd,
UINT uID1,
UINT uID2)
{
LPTSTR lpBuf = NULL;
DWORD BufSize = 0;
DWORD Type;
INT Ret = 0;
TCHAR szBuf[31];
TCHAR* szLastSpace;
INT LastSpace = 0;
if (RegQueryValueEx(hKey,
Value,
NULL,
&Type,
NULL,
&BufSize) == ERROR_SUCCESS)
{
lpBuf = HeapAlloc(GetProcessHeap(),
0,
BufSize);
if (!lpBuf) return 0;
LPTSTR lpBuf = NULL;
DWORD BufSize = 0;
DWORD Type;
INT Ret = 0;
TCHAR szBuf[31];
TCHAR* szLastSpace;
INT LastSpace = 0;
if (RegQueryValueEx(hKey,
Value,
NULL,
&Type,
NULL,
&BufSize) == ERROR_SUCCESS)
{
lpBuf = HeapAlloc(GetProcessHeap(),
0,
BufSize);
if (!lpBuf) return 0;
if (RegQueryValueEx(hKey,
Value,
NULL,
&Type,
(PBYTE)lpBuf,
&BufSize) == ERROR_SUCCESS)
{
if(BufSize > ((30 + 1) * sizeof(TCHAR)))
{
/* Wrap the Processor Name String like XP does: *
* - Take the first 30 characters and look for the last space. *
* Then wrap the string after this space. *
* - If no space is found, wrap the string after character 30. *
* *
* For example the Processor Name String of a Pentium 4 is right-aligned. *
* With this wrapping the first line looks centered. */
if (RegQueryValueEx(hKey,
Value,
NULL,
&Type,
(PBYTE)lpBuf,
&BufSize) == ERROR_SUCCESS)
{
if(BufSize > ((30 + 1) * sizeof(TCHAR)))
{
/* Wrap the Processor Name String like XP does: *
* - Take the first 30 characters and look for the last space. *
* Then wrap the string after this space. *
* - If no space is found, wrap the string after character 30. *
* *
* For example the Processor Name String of a Pentium 4 is right-aligned. *
* With this wrapping the first line looks centered. */
_tcsncpy(szBuf, lpBuf, 30);
szLastSpace = _tcsrchr(szBuf, ' ');
if(szLastSpace == 0)
LastSpace = 30;
else
LastSpace = (szLastSpace - szBuf);
_tcsncpy(szBuf, lpBuf, LastSpace);
szBuf[LastSpace] = 0;
SetDlgItemText(hwnd,
uID1,
szBuf);
SetDlgItemText(hwnd,
uID2,
lpBuf+LastSpace+1);
/* Return the number of used lines */
Ret = 2;
}
else
{
SetDlgItemText(hwnd,
uID1,
lpBuf);
Ret = 1;
}
}
_tcsncpy(szBuf, lpBuf, 30);
szBuf[30] = 0;
szLastSpace = _tcsrchr(szBuf, ' ');
HeapFree(GetProcessHeap(),
0,
lpBuf);
return Ret;
}
return 0;
if(szLastSpace == 0)
LastSpace = 30;
else
{
LastSpace = (szLastSpace - szBuf);
szBuf[LastSpace] = 0;
}
_tcsncpy(szBuf, lpBuf, LastSpace);
SetDlgItemText(hwnd,
uID1,
szBuf);
SetDlgItemText(hwnd,
uID2,
lpBuf+LastSpace+1);
/* Return the number of used lines */
Ret = 2;
}
else
{
SetDlgItemText(hwnd,
uID1,
lpBuf);
Ret = 1;
}
}
HeapFree(GetProcessHeap(),
0,
lpBuf);
return Ret;
}
return 0;
}
static VOID