Skip to content

Commit

Permalink
Address Printf formatting issues (#8378)
Browse files Browse the repository at this point in the history
* Address Printf formating issues

* Remove PID printing in TestInetCommonPosix.
  • Loading branch information
pan- authored Jul 15, 2021
1 parent b2d905e commit 1f020c5
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/app/tests/TestMessageDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CHIP_ERROR DebugPrettyPrint(const chip::System::PacketBufferHandle & aMsgBuf)

if (CHIP_NO_ERROR != err)
{
ChipLogProgress(DataManagement, "DebugPrettyPrint fails with err %d", err);
ChipLogProgress(DataManagement, "DebugPrettyPrint fails with err %" CHIP_ERROR_FORMAT, err);
}

return err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <ble/CHIPBleServiceData.h>
#include <core/CHIPConfig.h>
#include <inttypes.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/GenericConfigurationManagerImpl.h>
#include <support/Base64.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef GENERIC_PLATFORM_MANAGER_IMPL_CPP
#define GENERIC_PLATFORM_MANAGER_IMPL_CPP

#include <inttypes.h>
#include <new>
#include <platform/PlatformManager.h>
#include <platform/internal/BLEManager.h>
Expand Down
4 changes: 2 additions & 2 deletions src/inet/tests/TestInetAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ void CheckAddressQuartet(nlTestSuite * inSuite, const uint32_t & inFirstAddressQ

if (!lResult)
{
fprintf(stdout, "Address quartet %zu mismatch: actual 0x%08x, expected: 0x%08x\n", inWhich, inFirstAddressQuartet,
inSecondAddressQuartet);
fprintf(stdout, "Address quartet %zu mismatch: actual 0x%08" PRIX32 ", expected: 0x%08" PRIX32 "\n", inWhich,
inFirstAddressQuartet, inSecondAddressQuartet);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/inet/tests/TestInetCommonPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void ServiceEvents(struct ::timeval & aSleepTime)
if (NetworkIsReady())
#endif
{
printf("CHIP node ready to service events; PID: %d; PPID: %d\n", getpid(), getppid());
printf("CHIP node ready to service events\n");
fflush(stdout);
printed = true;
}
Expand Down Expand Up @@ -530,14 +530,14 @@ void ShutdownNetwork()

void DumpMemory(const uint8_t * mem, uint32_t len, const char * prefix, uint32_t rowWidth)
{
int indexWidth = snprintf(nullptr, 0, "%X", len);
int indexWidth = snprintf(nullptr, 0, "%" PRIX32, len);

if (indexWidth < 4)
indexWidth = 4;

for (uint32_t i = 0; i < len; i += rowWidth)
{
printf("%s%0*X: ", prefix, indexWidth, i);
printf("%s%0*" PRIX32 ": ", prefix, indexWidth, i);

uint32_t rowEnd = i + rowWidth;

Expand Down
2 changes: 1 addition & 1 deletion src/inet/tests/TestInetErrorStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void CheckInetErrorStr(nlTestSuite * inSuite, void * inContext)
Inet::RegisterLayerErrorFormatter();

// For each defined error...
for (int err : sContext)
for (int32_t err : sContext)
{
const char * errStr = ErrorStr(err);
char expectedText[9];
Expand Down
6 changes: 3 additions & 3 deletions src/inet/tests/TestInetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ bool HandleNonOptionArgs(const char * aProgram, int argc, char * argv[])

static void PrintReceivedStats(const TransferStats & aStats)
{
printf("%u/%u received\n", aStats.mReceive.mActual, aStats.mReceive.mExpected);
printf("%" PRIu32 "/%" PRIu32 "received\n", aStats.mReceive.mActual, aStats.mReceive.mExpected);
}

static bool HandleDataReceived(const PacketBufferHandle & aBuffer, bool aCheckBuffer, uint8_t aFirstValue)
Expand Down Expand Up @@ -891,8 +891,8 @@ void DriveSend()

sTestState.mStats.mTransmit.mActual += lSendSize;

printf("%u/%u transmitted to %s\n", sTestState.mStats.mTransmit.mActual, sTestState.mStats.mTransmit.mExpected,
sDestinationString);
printf("%" PRIu32 "/%" PRIu32 "transmitted to %s\n", sTestState.mStats.mTransmit.mActual,
sTestState.mStats.mTransmit.mExpected, sDestinationString);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/inet/tests/TestSetupFaultInjectionPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ static void PostInjectionCallbackFn(nl::FaultInjection::Manager * aManager, nl::
uint16_t numargs = aFaultRecord->mNumArguments;
uint16_t i;

printf("***** Injecting fault %s_%s, instance number: %u; reboot: %s", aManager->GetName(), aManager->GetFaultNames()[aId],
aFaultRecord->mNumTimesChecked, aFaultRecord->mReboot ? "yes" : "no");
printf("***** Injecting fault %s_%s, instance number: %" PRIu32 "; reboot: %s", aManager->GetName(),
aManager->GetFaultNames()[aId], aFaultRecord->mNumTimesChecked, aFaultRecord->mReboot ? "yes" : "no");
if (numargs)
{
printf(" with %u args:", numargs);

for (i = 0; i < numargs; i++)
{
printf(" %d", aFaultRecord->mArguments[i]);
printf(" %" PRIi32, aFaultRecord->mArguments[i]);
}
}

Expand All @@ -138,8 +138,8 @@ static bool PrintFaultInjectionMaxArgCbFn(nl::FaultInjection::Manager & mgr, nl:

if (gFaultInjectionOptions.PrintFaultCounters && aFaultRecord->mNumArguments)
{
printf("FI_instance_params: %s_%s_s%u maxArg: %u;\n", mgr.GetName(), faultName, aFaultRecord->mNumTimesChecked,
aFaultRecord->mArguments[0]);
printf("FI_instance_params: %s_%s_s%" PRIu32 " maxArg: %" PRIi32 ";\n", mgr.GetName(), faultName,
aFaultRecord->mNumTimesChecked, aFaultRecord->mArguments[0]);
}

return false;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/mdns/tests/TestTxtFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void TestGetProduct(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 0);

// overflow a uint16
sprintf(vp, "123+%u", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
sprintf(vp, "123+%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 0);
}
void TestGetVendor(nlTestSuite * inSuite, void * inContext)
Expand All @@ -128,7 +128,7 @@ void TestGetVendor(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 123);

// overflow a uint16
sprintf(vp, "%u+456", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
sprintf(vp, "%" PRIu32 "+456", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 0);
}

Expand All @@ -139,7 +139,7 @@ void TestGetLongDiscriminator(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, GetLongDisriminator(GetSpan(ld)) == 1234);

// overflow a uint16
sprintf(ld, "%u", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
sprintf(ld, "%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
printf("ld = %s\n", ld);
NL_TEST_ASSERT(inSuite, GetLongDisriminator(GetSpan(ld)) == 0);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ void TestGetDeviceType(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, GetDeviceType(GetSpan(dt)) == 1234);

// overflow a uint16
sprintf(dt, "%u", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
sprintf(dt, "%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
NL_TEST_ASSERT(inSuite, GetDeviceType(GetSpan(dt)) == 0);
}

Expand Down Expand Up @@ -249,7 +249,7 @@ void TestGetPairingHint(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, GetPairingHint(GetSpan(ph)) == 9);

// overflow a uint16
sprintf(ph, "%u", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
sprintf(ph, "%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
NL_TEST_ASSERT(inSuite, GetPairingHint(GetSpan(ph)) == 0);
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/support/tests/TestTimeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ void TestDaysSinceEpochConversion()
CalendarDateToDaysSinceUnixEpoch(year, month, dayOfMonth, calculatedDaysSinceEpoch);

if (calculatedDaysSinceEpoch != daysSinceEpoch)
printf("%04u/%02u/%02u %u %u\n", year, month, dayOfMonth, daysSinceEpoch, calculatedDaysSinceEpoch);
printf("%04u/%02u/%02u %" PRIu32 " %" PRIu32 "\n", year, month, dayOfMonth, daysSinceEpoch,
calculatedDaysSinceEpoch);

TestAssert(calculatedDaysSinceEpoch == daysSinceEpoch,
"CalendarDateToDaysSinceUnixEpoch() returned unexpected value");
Expand Down

0 comments on commit 1f020c5

Please sign in to comment.