[GDI32] Reduce verbosity on debug builds
[reactos.git] / win32ss / gdi / gdi32 / objects / font.c
index e20c070..8789223 100644 (file)
@@ -295,7 +295,9 @@ IntEnumFontFamilies(HDC Dc, const LOGFONTW *LogFont, PVOID EnumProc, LPARAM lPar
     ENUMLOGFONTEXA EnumLogFontExA;
     NEWTEXTMETRICEXA NewTextMetricExA;
     LOGFONTW lfW;
-    LONG DataSize, InfoCount;
+    LONG InfoCount;
+    ULONG DataSize;
+    NTSTATUS Status;
 
     DataSize = INITIAL_FAMILY_COUNT * sizeof(FONTFAMILYINFO);
     Info = RtlAllocateHeap(GetProcessHeap(), 0, DataSize);
@@ -330,7 +332,13 @@ IntEnumFontFamilies(HDC Dc, const LOGFONTW *LogFont, PVOID EnumProc, LPARAM lPar
     if (INITIAL_FAMILY_COUNT < InfoCount)
     {
         RtlFreeHeap(GetProcessHeap(), 0, Info);
-        DataSize = InfoCount * sizeof(FONTFAMILYINFO);
+
+        Status = RtlULongMult(InfoCount, sizeof(FONTFAMILYINFO), &DataSize);
+        if (!NT_SUCCESS(Status) || DataSize > LONG_MAX)
+        {
+            DPRINT1("Overflowed.\n");
+            return 1;
+        }
         Info = RtlAllocateHeap(GetProcessHeap(), 0, DataSize);
         if (Info == NULL)
         {
@@ -1332,7 +1340,7 @@ GetOutlineTextMetricsA(
     else
         output->otmpFullName = 0;
 
-    assert(left == 0);
+    ASSERT(left == 0);
 
     if(output != lpOTM)
     {
@@ -1722,6 +1730,13 @@ VOID DumpFamilyInfo(const FONTFAMILYINFO *Info, LONG Count)
 
 VOID DoFontSystemUnittest(VOID)
 {
+#ifndef RTL_SOFT_ASSERT
+#define RTL_SOFT_ASSERT(exp) \
+  (void)((!(exp)) ? \
+    DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)
+#define RTL_SOFT_ASSERT_defined
+#endif
+
     LOGFONTW LogFont;
     FONTFAMILYINFO Info[4];
     UNICODE_STRING Str1, Str2;
@@ -1736,8 +1751,8 @@ VOID DoFontSystemUnittest(VOID)
     ret = NtGdiGetFontFamilyInfo(NULL, &LogFont, Info, &InfoCount);
     DPRINT1("ret: %ld, InfoCount: %ld\n", ret, InfoCount);
     DumpFamilyInfo(Info, ret);
-    ASSERT(ret == RTL_NUMBER_OF(Info));
-    ASSERT(InfoCount > 32);
+    RTL_SOFT_ASSERT(ret == RTL_NUMBER_OF(Info));
+    RTL_SOFT_ASSERT(InfoCount > 32);
 
     /* L"Microsoft Sans Serif" ANSI_CHARSET */
     RtlZeroMemory(&LogFont, sizeof(LogFont));
@@ -1747,19 +1762,19 @@ VOID DoFontSystemUnittest(VOID)
     ret = NtGdiGetFontFamilyInfo(NULL, &LogFont, Info, &InfoCount);
     DPRINT1("ret: %ld, InfoCount: %ld\n", ret, InfoCount);
     DumpFamilyInfo(Info, ret);
-    ASSERT(ret != -1);
-    ASSERT(InfoCount > 0);
-    ASSERT(InfoCount < 16);
+    RTL_SOFT_ASSERT(ret != -1);
+    RTL_SOFT_ASSERT(InfoCount > 0);
+    RTL_SOFT_ASSERT(InfoCount < 16);
 
     RtlInitUnicodeString(&Str1, Info[0].EnumLogFontEx.elfLogFont.lfFaceName);
     RtlInitUnicodeString(&Str2, L"Microsoft Sans Serif");
     ret = RtlCompareUnicodeString(&Str1, &Str2, TRUE);
-    ASSERT(ret == 0);
+    RTL_SOFT_ASSERT(ret == 0);
 
     RtlInitUnicodeString(&Str1, Info[0].EnumLogFontEx.elfFullName);
     RtlInitUnicodeString(&Str2, L"Tahoma");
     ret = RtlCompareUnicodeString(&Str1, &Str2, TRUE);
-    ASSERT(ret == 0);
+    RTL_SOFT_ASSERT(ret == 0);
 
     /* L"Non-Existent" DEFAULT_CHARSET */
     RtlZeroMemory(&LogFont, sizeof(LogFont));
@@ -1769,8 +1784,13 @@ VOID DoFontSystemUnittest(VOID)
     ret = NtGdiGetFontFamilyInfo(NULL, &LogFont, Info, &InfoCount);
     DPRINT1("ret: %ld, InfoCount: %ld\n", ret, InfoCount);
     DumpFamilyInfo(Info, ret);
-    ASSERT(ret == 0);
-    ASSERT(InfoCount == 0);
+    RTL_SOFT_ASSERT(ret == 0);
+    RTL_SOFT_ASSERT(InfoCount == 0);
+
+#ifdef RTL_SOFT_ASSERT_defined
+#undef RTL_SOFT_ASSERT_defined
+#undef RTL_SOFT_ASSERT
+#endif
 }
 #endif
 
@@ -1784,12 +1804,12 @@ CreateFontIndirectW(
     CONST LOGFONTW             *lplf
 )
 {
-#if DBG
+#if 0
     static BOOL bDidTest = FALSE;
     if (!bDidTest)
     {
-        DoFontSystemUnittest();
         bDidTest = TRUE;
+        DoFontSystemUnittest();
     }
 #endif
     if (lplf)