From 3087c56ea17712a5746907a6f2ff44d41f5cc9a5 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Sun, 22 Jul 2007 19:31:29 +0000 Subject: [PATCH] - 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 --- reactos/dll/cpl/sysdm/general.c | 153 ++++++++++++++++---------------- 1 file changed, 78 insertions(+), 75 deletions(-) diff --git a/reactos/dll/cpl/sysdm/general.c b/reactos/dll/cpl/sysdm/general.c index 7e2eb8632a3..5bb00d6b573 100644 --- a/reactos/dll/cpl/sysdm/general.c +++ b/reactos/dll/cpl/sysdm/general.c @@ -5,7 +5,7 @@ * PURPOSE: General System Information * COPYRIGHT: Copyright Thomas Weidenmueller * Copyright 2006 Ged Murphy - * Copyright 2006 Colin Finck + * Copyright 2006-2007 Colin Finck * */ @@ -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