2

I have been debugging this RTOS code in Coverity and ran into few small errors. The errors are self explanatory as they are format specifier errors. Both of the errors are on the main function. The first error is on the line:

RTOS_TEST(" Error = 0x%X, pool = 0x%X\n", result, (_mqx_uint)error_ptr);

Error: Invalid type in argument to printf format specifier (PRINTF_ARGS) invalid_type: Argument result to format specifier %X was expected to have type unsigned int but has type unsigned long.

The second error is on the line:

RTOS_TEST("MQX lock mutex FAILED: 0x08X\n", status);

Error: Extra argument to printf format specifier (PRINTF_ARGS) extra_argument: This argument was not used by the format string: status.

I am not sure how I am passing an extra argument as the RTOS_TEST does take one argument. Please tell me what I am doing wrong.

#if !defined(__arc__)
   #define RTOS_TEST(...) printf(__VA_ARGS__)
#else
   #define RTOS_TEST(...)
#endif

typedef uint_32  _mqx_uint, _PTR_ _mqx_uint_ptr;
typedef uint32_t Status_t;

void SECTION_CODE("CODE_SLOW") WrappersTest(uint_32  parameter)
{
   _lwmem_pool_id lwmem_pool_id;
   pointer        error_ptr;
   pointer        error2_ptr;
   Status_t       status;
   _mqx_uint      result;
   BOOL           fail = FALSE;

   RTOS_TEST("Start MQX integrity tests ...\n");

   TestQueue();
   TestLightWeightSemaphore();
   TestMutexAPI();
   TestLightWeightEvent();
   TestFastMessageQueue();
   TestLightWeightMemory();

#if defined(MQX_TEST_EVENT_TEST)
   RTOS_TEST("Calling _event_test ..."); fflush(stdout);
   result = _event_test(&error_ptr);

   if (result != MQX_OK)
   {
      RTOS_TEST(" ***FAILED*** _event_test: 0x%08X\n", result);
      fail = TRUE;
   }
   else
   {
      RTOS_TEST("PASSED!\n");
   }
#endif // MQX_TEST_EVENT_TEST

status = RTOS_MutexInit(&testMutex, (uint8_t*)Name);

if (status != STATUS_OK)
{
   RTOS_TEST("MQX init mutex FAILED: 0x%08X\n", status);
}

for (; loopCount > 0; loopCount--)
{
   status = RTOS_MutexLock(&testMutex);

   if (status != STATUS_OK)
   {
      RTOS_TEST("MQX lock mutex FAILED: 0x08X\n", status);
   }
}

int main()
{
   .........,
   RTOS_TEST(" Error = 0x%X, pool = 0x%X\n", result, (_mqx_uint)error_ptr);
   ..........
   if (status != STATUS_OK)
         {
            RTOS_TEST("MQX lock mutex FAILED: 0x08X\n", status);
         }
   ..........
   return 0;
}
Ashish101
  • 135
  • 10

2 Answers2

1

In this call

RTOS_TEST("MQX lock mutex FAILED: 0x08X\n", status);

you at least forgot to specify the symbol '%' before the format specifier 'X' For example "0x%08X". So the compiler issues an error referring to the argument status that there are redundant arguments

In this call

RTOS_TEST(" Error = 0x%X, pool = 0x%X\n", result, (_mqx_uint)error_ptr);

you have to specify the length modifier 'l'.

For example

RTOS_TEST(" Error = %#lX, pool = %#lX\n", result, (_mqx_uint)error_ptr);

Pay attention that there is no need to write 0x. Instead you can use the flag '#'. If you want to have the prefix '0x' then use lower case format specifier 'x' like"%#lx". Otherwise use the upper case format specifier'X'like"%#lX"`.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

"MQX lock mutex FAILED: 0x08X\n", status is simply missing the "%" as well answered by @Vlad from Moscow.
Good that OP has many warnings/errors enabled.


Concerning type mismatches, use the matching print specifier.

Example: as status is a uint32_t, use "%" PRIX32

#include <inttypes.h>

typedef uint32_t Status_t;
Status_t       status;

// RTOS_TEST("MQX lock mutex FAILED: 0x08X\n", status);
RTOS_TEST("MQX lock mutex FAILED: 0x%08" PRIX32 "\n", status);
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256