VirtualBox

Changeset 95809 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 25, 2022 1:19:34 PM (2 years ago)
Author:
vboxsync
Message:

IPRT/assert.cpp: Use RTLogWriteStdErr instead of fprintf/stderr in IPRT_NO_CRT mode. bugref:10261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/assert.cpp

    r93115 r95809  
    4545#ifdef IN_RING3
    4646# include <iprt/env.h>
    47 # include <stdio.h>
     47# ifndef IPRT_NO_CRT
     48#  include <stdio.h>
     49# endif
    4850# ifdef RT_OS_WINDOWS
    4951#  include <iprt/win/windows.h>
     
    220222# ifdef IN_RING3
    221223        /* print to stderr, helps user and gdb debugging. */
     224#  ifndef IPRT_NO_CRT
    222225        fprintf(stderr,
    223226                "\n!!Assertion Failed!!\n"
     
    228231                uLine,
    229232                RT_VALID_PTR(pszFunction) ? pszFunction : "");
    230 # ifdef IPRT_WITH_ASSERT_STACK
     233#   ifdef IPRT_WITH_ASSERT_STACK
    231234        fprintf(stderr, "Stack     :\n%s\n", szStack);
    232 # endif
     235#   endif
    233236        fflush(stderr);
     237#  else
     238        char szMsg[2048];
     239        size_t cchMsg = RTStrPrintf(szMsg, sizeof(szMsg),
     240                                    "\n!!Assertion Failed!!\n"
     241                                    "Expression: %s\n"
     242                                    "Location  : %s(%d) %s\n",
     243                                    RT_VALID_PTR(pszExpr) ? pszExpr : "<none>",
     244                                    RT_VALID_PTR(pszFile) ? pszFile : "<none>",
     245                                    uLine,
     246                                    RT_VALID_PTR(pszFunction) ? pszFunction : "");
     247        RTLogWriteStdErr(szMsg, cchMsg);
     248#   ifdef IPRT_WITH_ASSERT_STACK
     249        RTLogWriteStdErr(RT_STR_TUPLE("Stack     :\n"));
     250        RTLogWriteStdErr(szStack, strlen(szStack));
     251        RTLogWriteStdErr(RT_STR_TUPLE("\n"));
     252#   endif
     253#  endif
    234254# endif
    235255#endif /* !IN_RING0 */
     
    327347        char szMsg[sizeof(g_szRTAssertMsg2)];
    328348        va_copy(vaCopy, va);
    329         RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
     349        size_t cchMsg = RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
    330350        va_end(vaCopy);
    331         fprintf(stderr, "%s", szMsg);
     351#  ifndef IPRT_NO_CRT
     352        fwrite(szMsg, 1, cchMsg, stderr);
    332353        fflush(stderr);
     354#  else
     355        RTLogWriteStdErr(szMsg, cchMsg);
     356#  endif
    333357# endif
    334358#endif /* !IN_RING0 */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette