Fix a warning (treated as an error).
[reactos.git] / reactos / subsystems / win32 / csrss / win32csr / harderror.c
index a1b5a5d..55973e6 100644 (file)
@@ -84,8 +84,8 @@ CsrpGetClientFileName(
 
     ClientFileNameU->MaximumLength = ModuleData.BaseDllName.MaximumLength;
     ClientFileNameU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
-                                              HEAP_ZERO_MEMORY,
-                                              ClientFileNameU->MaximumLength);
+                              HEAP_ZERO_MEMORY,
+                              ClientFileNameU->MaximumLength);
 
     Status = NtReadVirtualMemory(hProcess,
                                  ModuleData.BaseDllName.Buffer,
@@ -123,9 +123,9 @@ CsrpCaptureStringParameters(
     UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask;
 
     /* Read all strings from client space */
-    for (nParam = 0; 
-         nParam < HardErrorMessage->NumberOfParameters; 
-         nParam++, UnicodeStringParameterMask >>= 1)
+    for (nParam = 0;
+            nParam < HardErrorMessage->NumberOfParameters;
+            nParam++, UnicodeStringParameterMask >>= 1)
     {
         Parameters[nParam] = 0;
 
@@ -194,9 +194,9 @@ CsrpFreeStringParameters(
     UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask;
 
     /* Loop all parameters */
-    for (nParam = 0; 
-         nParam < HardErrorMessage->NumberOfParameters; 
-         nParam++, UnicodeStringParameterMask >>= 1)
+    for (nParam = 0;
+            nParam < HardErrorMessage->NumberOfParameters;
+            nParam++, UnicodeStringParameterMask >>= 1)
     {
         /* Check if the current parameter is a string */
         if (UnicodeStringParameterMask & 0x01)
@@ -221,9 +221,9 @@ CsrpFormatMessages(
     NTSTATUS Status;
     UNICODE_STRING FileNameU, TempStringU, FormatU;
     ANSI_STRING FormatA;
-    PRTL_MESSAGE_RESOURCE_ENTRY MessageResource;
+    PMESSAGE_RESOURCE_ENTRY MessageResource;
     PWSTR FormatString;
-    ULONG Size;
+    ULONG Size, ExceptionCode;
 
     /* Get the file name of the client process */
     CsrpGetClientFileName(&FileNameU, hProcess);
@@ -251,7 +251,7 @@ CsrpFormatMessages(
         }
         else
         {
-            RtlInitAnsiString(&FormatA, MessageResource->Text);
+            RtlInitAnsiString(&FormatA, (PCHAR)MessageResource->Text);
             RtlAnsiStringToUnicodeString(&FormatU, &FormatA, TRUE);
         }
     }
@@ -292,8 +292,8 @@ CsrpFormatMessages(
 
     /* Allocate a buffer for the caption */
     CaptionStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
-                                             HEAP_ZERO_MEMORY,
-                                             CaptionStringU->MaximumLength);
+                             HEAP_ZERO_MEMORY,
+                             CaptionStringU->MaximumLength);
 
     /* Append the file name, seperator and the caption text */
     CaptionStringU->Length = 0;
@@ -310,8 +310,10 @@ CsrpFormatMessages(
     /* Check if this is an exception message */
     if (Message->Status == STATUS_UNHANDLED_EXCEPTION)
     {
+        ExceptionCode = Parameters[0];
+
         /* Handle special cases */
-        if (Parameters[0] == STATUS_ACCESS_VIOLATION)
+        if (ExceptionCode == STATUS_ACCESS_VIOLATION)
         {
             Parameters[0] = Parameters[1];
             Parameters[1] = Parameters[3];
@@ -319,7 +321,7 @@ CsrpFormatMessages(
             else Parameters[2] = (ULONG_PTR)L"read";
             MessageResource = NULL;
         }
-        else if (Parameters[0] == STATUS_IN_PAGE_ERROR)
+        else if (ExceptionCode == STATUS_IN_PAGE_ERROR)
         {
             Parameters[0] = Parameters[1];
             Parameters[1] = Parameters[3];
@@ -339,7 +341,7 @@ CsrpFormatMessages(
             Status = RtlFindMessage(GetModuleHandleW(L"ntdll"),
                                     (ULONG_PTR)RT_MESSAGETABLE,
                                     LANG_NEUTRAL,
-                                    Parameters[0],
+                                    ExceptionCode,
                                     &MessageResource);
 
             if (NT_SUCCESS(Status))
@@ -353,9 +355,10 @@ CsrpFormatMessages(
                 }
                 else
                 {
-                    RtlInitAnsiString(&FormatA, MessageResource->Text);
+                    RtlInitAnsiString(&FormatA, (PCHAR)MessageResource->Text);
                     RtlAnsiStringToUnicodeString(&FormatU, &FormatA, TRUE);
                 }
+                FormatString = FormatU.Buffer;
             }
             else
             {
@@ -368,9 +371,8 @@ CsrpFormatMessages(
     }
 
     /* Calculate length of text buffer */
-    TextStringU->MaximumLength = wcslen(FormatString) * sizeof(WCHAR) +
-                                     SizeOfStrings + 42 * sizeof(WCHAR);
-    
+    TextStringU->MaximumLength = FormatU.Length + SizeOfStrings + 42 * sizeof(WCHAR);
+
     /* Allocate a buffer for the text */
     TextStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
                                           HEAP_ZERO_MEMORY,
@@ -381,13 +383,13 @@ CsrpFormatMessages(
     {
         /* Print the string into the buffer */
         StringCbPrintfW(TextStringU->Buffer,
-                        TextStringU->MaximumLength,
-                        FormatString,
-                        Parameters[0],
-                        Parameters[1],
-                        Parameters[2],
-                        Parameters[3],
-                        Parameters[4]);
+        TextStringU->MaximumLength,
+        FormatString,
+        Parameters[0],
+        Parameters[1],
+        Parameters[2],
+        Parameters[3],
+        Parameters[4]);
         Status = STATUS_SUCCESS;
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
@@ -422,30 +424,30 @@ CsrpMessageBox(
     /* Set the message box type */
     switch (ValidResponseOptions)
     {
-        case OptionAbortRetryIgnore:
-            Type = MB_ABORTRETRYIGNORE;
-            break;
-        case OptionOk:
-            Type = MB_OK;
-            break;
-        case OptionOkCancel:
-            Type = MB_OKCANCEL;
-            break;
-        case OptionRetryCancel:
-            Type = MB_RETRYCANCEL;
-            break;
-        case OptionYesNo:
-            Type = MB_YESNO;
-            break;
-        case OptionYesNoCancel:
-            Type = MB_YESNOCANCEL;
-            break;
-        case OptionShutdownSystem:
-            Type = MB_RETRYCANCEL; // FIXME???
-            break;
+    case OptionAbortRetryIgnore:
+        Type = MB_ABORTRETRYIGNORE;
+        break;
+    case OptionOk:
+        Type = MB_OK;
+        break;
+    case OptionOkCancel:
+        Type = MB_OKCANCEL;
+        break;
+    case OptionRetryCancel:
+        Type = MB_RETRYCANCEL;
+        break;
+    case OptionYesNo:
+        Type = MB_YESNO;
+        break;
+    case OptionYesNoCancel:
+        Type = MB_YESNOCANCEL;
+        break;
+    case OptionShutdownSystem:
+        Type = MB_RETRYCANCEL; // FIXME???
+        break;
         /* Anything else is invalid */
-        default:
-            return ResponseNotHandled;
+    default:
+        return ResponseNotHandled;
     }
 
     /* Set severity */
@@ -455,7 +457,7 @@ CsrpMessageBox(
 
     Type |= MB_SYSTEMMODAL | MB_SETFOREGROUND;
 
-    DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n", 
+    DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n",
            Text, Caption, Severity, Type);
 
     /* Display a message box */
@@ -464,15 +466,15 @@ CsrpMessageBox(
     /* Return response value */
     switch (MessageBoxResponse)
     {
-        case IDOK:       return ResponseOk;
-        case IDCANCEL:   return ResponseCancel;
-        case IDYES:      return ResponseYes;
-        case IDNO:       return ResponseNo;
-        case IDABORT:    return ResponseAbort;
-        case IDIGNORE:   return ResponseIgnore;
-        case IDRETRY:    return ResponseRetry;
-        case IDTRYAGAIN: return ResponseTryAgain;
-        case IDCONTINUE: return ResponseContinue;
+    case IDOK:       return ResponseOk;
+    case IDCANCEL:   return ResponseCancel;
+    case IDYES:      return ResponseYes;
+    case IDNO:       return ResponseNo;
+    case IDABORT:    return ResponseAbort;
+    case IDIGNORE:   return ResponseIgnore;
+    case IDRETRY:    return ResponseRetry;
+    case IDTRYAGAIN: return ResponseTryAgain;
+    case IDCONTINUE: return ResponseContinue;
     }
 
     return ResponseNotHandled;
@@ -535,7 +537,7 @@ Win32CsrHardError(
 
     if (!NT_SUCCESS(Status))
     {
-       return FALSE;
+        return FALSE;
     }
 
     /* Display the message box */