From fe8ef98e2c1611a72bd2840cd08dc101f25b1cd3 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 9 Oct 2013 12:15:06 +0300 Subject: Use assertions to ensure proper use of the osl command line arg API Stephan says: I don't buy that argument of making things less fragile; IMO it's that "defensive programming" approach gone wrong, where you add complexity to mitigate a problem's effects in one place, instead of fixing the problem itself in the real place. [...] The better robustification is probably to turn the OSL_TRACE in osl_getCommandArgCount (sal/osl/unx/process_impl.cxx) into something stronger like SAL_WARN, assert, or std::abort Change-Id: I3ba6684b4921eb67c2f4534e29e33056e8a891b3 --- sal/osl/unx/process_impl.cxx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'sal') diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx index bd1e5a2f9726..00766ccf4304 100644 --- a/sal/osl/unx/process_impl.cxx +++ b/sal/osl/unx/process_impl.cxx @@ -176,11 +176,7 @@ sal_uInt32 SAL_CALL osl_getCommandArgCount (void) sal_uInt32 result = 0; pthread_mutex_lock (&(g_command_args.m_mutex)); - if (g_command_args.m_nCount == 0) { - OSL_TRACE( - OSL_LOG_PREFIX - "osl_getCommandArgCount w/o prior call to osl_setCommandArgs"); - } + assert (g_command_args.m_nCount != 0); if (g_command_args.m_nCount > 0) result = g_command_args.m_nCount - 1; pthread_mutex_unlock (&(g_command_args.m_mutex)); @@ -214,7 +210,7 @@ void SAL_CALL osl_setCommandArgs (int argc, char ** argv) { OSL_ASSERT(argc > 0); pthread_mutex_lock (&(g_command_args.m_mutex)); - OSL_ENSURE (g_command_args.m_nCount == 0, "osl_setCommandArgs(): CommandArgs already set."); + assert (g_command_args.m_nCount == 0); if (g_command_args.m_nCount == 0) { rtl_uString** ppArgs = (rtl_uString**)rtl_allocateZeroMemory (argc * sizeof(rtl_uString*)); -- cgit