Author: hbelusca
Date: Sat Aug 6 16:21:02 2016
New Revision: 72140
URL:
http://svn.reactos.org/svn/reactos?rev=72140&view=rev
Log:
[EVENTVWR]
Don't hardcode a fixed size for the memory buffer holding the event details data to be
copied into the clipboard, but instead compute it using the real lengths of the different
strings. Use also StringCbPrintfW instead.
Modified:
trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.h
trunk/reactos/base/applications/mscutils/eventvwr/evtdetctl.c
Modified: trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/eventvwr/eventvwr.h [iso-8859-1] Sat Aug 6
16:21:02 2016
@@ -29,6 +29,8 @@
#define ROUND_DOWN(n, align) (((ULONG)n) & ~((align) - 1l))
#define ROUND_UP(n, align) ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
+
+#include <strsafe.h>
#include <commctrl.h>
#include <commdlg.h>
Modified: trunk/reactos/base/applications/mscutils/eventvwr/evtdetctl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/eventvwr/evtdetctl.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/eventvwr/evtdetctl.c [iso-8859-1] Sat Aug 6
16:21:02 2016
@@ -10,8 +10,6 @@
#include "eventvwr.h"
#include "evtdetctl.h"
-
-#define ENTRY_SIZE 2056
// FIXME:
#define EVENT_MESSAGE_EVENTTEXT_BUFFER 1024*10
@@ -262,17 +260,17 @@
{
LOGFONTW tmpFont = {0};
HFONT hFont;
- HDC hDc;
-
- hDc = GetDC(NULL);
-
- tmpFont.lfHeight = -MulDiv(8, GetDeviceCaps(hDc, LOGPIXELSY), 72);
+ HDC hDC;
+
+ hDC = GetDC(NULL);
+
+ tmpFont.lfHeight = -MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72);
tmpFont.lfWeight = FW_NORMAL;
wcscpy(tmpFont.lfFaceName, L"Courier New");
hFont = CreateFontIndirectW(&tmpFont);
- ReleaseDC(NULL, hDc);
+ ReleaseDC(NULL, hDC);
return hFont;
}
@@ -281,7 +279,7 @@
VOID
CopyEventEntry(HWND hWnd)
{
- WCHAR output[4130], tmpHeader[512];
+ WCHAR tmpHeader[512];
WCHAR szEventType[MAX_PATH];
WCHAR szSource[MAX_PATH];
WCHAR szCategory[MAX_PATH];
@@ -290,41 +288,58 @@
WCHAR szTime[MAX_PATH];
WCHAR szUser[MAX_PATH];
WCHAR szComputer[MAX_PATH];
- WCHAR evtDesc[ENTRY_SIZE];
+ WCHAR evtDesc[EVENT_MESSAGE_EVENTTEXT_BUFFER];
+ ULONG size = 0;
+ LPWSTR output;
HGLOBAL hMem;
+ /* Try to open the clipboard */
if (!OpenClipboard(hWnd))
return;
- /* First, empty the clipboard before we begin to use it */
+ /* Get the formatted text needed to place the content into */
+ size += LoadStringW(hInst, IDS_COPY, tmpHeader, ARRAYSIZE(tmpHeader));
+
+ /* Grab all the information and get it ready for the clipboard */
+ size += GetDlgItemTextW(hWnd, IDC_EVENTTYPESTATIC, szEventType,
ARRAYSIZE(szEventType));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTSOURCESTATIC, szSource, ARRAYSIZE(szSource));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTCATEGORYSTATIC, szCategory,
ARRAYSIZE(szCategory));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTIDSTATIC, szEventID, ARRAYSIZE(szEventID));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTDATESTATIC, szDate, ARRAYSIZE(szDate));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTTIMESTATIC, szTime, ARRAYSIZE(szTime));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTUSERSTATIC, szUser, ARRAYSIZE(szUser));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTCOMPUTERSTATIC, szComputer,
ARRAYSIZE(szComputer));
+ size += GetDlgItemTextW(hWnd, IDC_EVENTTEXTEDIT, evtDesc, ARRAYSIZE(evtDesc));
+
+ size++; /* Null-termination */
+ size *= sizeof(WCHAR);
+
+ /*
+ * Consolidate the information into one big piece and
+ * sort out the memory needed to write to the clipboard.
+ */
+ hMem = GlobalAlloc(GMEM_MOVEABLE, size);
+ if (hMem == NULL) goto Quit;
+
+ output = GlobalLock(hMem);
+ if (output == NULL)
+ {
+ GlobalFree(hMem);
+ goto Quit;
+ }
+
+ StringCbPrintfW(output, size,
+ tmpHeader, szEventType, szSource, szCategory, szEventID,
+ szDate, szTime, szUser, szComputer, evtDesc);
+
+ GlobalUnlock(hMem);
+
+ /* We succeeded, empty the clipboard and write the data in it */
EmptyClipboard();
-
- /* Get the formatted text needed to place the content into */
- LoadStringW(hInst, IDS_COPY, tmpHeader, ARRAYSIZE(tmpHeader));
-
- /* Grab all the information and get it ready for the clipboard */
- GetDlgItemTextW(hWnd, IDC_EVENTTYPESTATIC, szEventType, ARRAYSIZE(szEventType));
- GetDlgItemTextW(hWnd, IDC_EVENTSOURCESTATIC, szSource, ARRAYSIZE(szSource));
- GetDlgItemTextW(hWnd, IDC_EVENTCATEGORYSTATIC, szCategory, ARRAYSIZE(szCategory));
- GetDlgItemTextW(hWnd, IDC_EVENTIDSTATIC, szEventID, ARRAYSIZE(szEventID));
- GetDlgItemTextW(hWnd, IDC_EVENTDATESTATIC, szDate, ARRAYSIZE(szDate));
- GetDlgItemTextW(hWnd, IDC_EVENTTIMESTATIC, szTime, ARRAYSIZE(szTime));
- GetDlgItemTextW(hWnd, IDC_EVENTUSERSTATIC, szUser, ARRAYSIZE(szUser));
- GetDlgItemTextW(hWnd, IDC_EVENTCOMPUTERSTATIC, szComputer, ARRAYSIZE(szComputer));
- GetDlgItemTextW(hWnd, IDC_EVENTTEXTEDIT, evtDesc, ARRAYSIZE(evtDesc));
-
- /* Consolidate the information into on big piece */
- wsprintfW(output, tmpHeader, szEventType, szSource, szCategory, szEventID, szDate,
szTime, szUser, szComputer, evtDesc);
-
- /* Sort out the memory needed to write to the clipboard */
- hMem = GlobalAlloc(GMEM_MOVEABLE, ENTRY_SIZE);
- memcpy(GlobalLock(hMem), output, ENTRY_SIZE);
- GlobalUnlock(hMem);
-
- /* Write the final content to the clipboard */
SetClipboardData(CF_UNICODETEXT, hMem);
- /* Close the clipboard once we're done with it */
+Quit:
+ /* Close the clipboard once we are done with it */
CloseClipboard();
}