Skip to content

Commit

Permalink
Stop using PRI*8 printf formats. (#15099)
Browse files Browse the repository at this point in the history
These are not supported on some embedded/minimal libcs.  Use %u/%d/%x
instead, since [u]int8_t will get promoted to int anyway when passed
via varargs.

This commit was generated by installing the git-extras package and running:

    git sed -f g '" PRIu8 "' 'u'
    git sed -f g '" PRIu8' 'u"'
    git sed -f g '" PRIx8 "' 'x'
    git sed -f g '" PRIx8' 'x"'
    git sed -f g '" PRIX8 "' 'X'
    git sed -f g '" PRIX8' 'X"'
    git sed -f g '" PRId8 "' 'd'
    git sed -f g '" PRId8' 'd"'

followed by the following manual fixups:

1) Fixing a comment in src/app/MessageDef/StatusIB.cpp
2) Deleting an unused macro in src/system/SystemStats.h
3) Reverting the change the above git sed commands caused in
   third_party/lwip/repo/lwip/src/include/lwip/arch.h
4) Adding a lint.
5) Running restyle.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 22, 2023
1 parent 9d4401a commit 8a6be2a
Show file tree
Hide file tree
Showing 51 changed files with 217 additions and 231 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ jobs:
run: |
git grep -n "VerifyOrExit(.*, [A-Za-z]*_ERROR" -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
# git grep exits with 0 if it finds a match, but we want
# to fail (exit nonzero) on match. And we wasnt to exclude this file,
# to avoid our grep regexp matching itself.
- name: Check for use of PRI*8, which are not supported on some libcs.
if: always()
run: |
git grep -n "PRI.8" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)third_party/lwip/repo/lwip/src/include/lwip/arch.h' && exit 1 || exit 0
# Comments like '{{! ... }}' should be used in zap files
- name: Do not allow TODO in generated files
if: always()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short en
return EMBER_ZCL_STATUS_SUCCESS;
}
}
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %" PRIu8, mode);
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %u", mode);
return EMBER_ZCL_STATUS_INVALID_VALUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CHIP_ERROR SetupPayloadParseCommand::Parse(std::string codeString, chip::SetupPa

CHIP_ERROR SetupPayloadParseCommand::Print(chip::SetupPayload payload)
{
ChipLogProgress(SetupPayload, "CommissioningFlow: %" PRIu8, to_underlying(payload.commissioningFlow));
ChipLogProgress(SetupPayload, "CommissioningFlow: %u", to_underlying(payload.commissioningFlow));
ChipLogProgress(SetupPayload, "VendorID: %u", payload.vendorID);
ChipLogProgress(SetupPayload, "Version: %u", payload.version);
ChipLogProgress(SetupPayload, "ProductID: %u", payload.productID);
Expand Down
37 changes: 18 additions & 19 deletions examples/door-lock-app/linux/src/LockEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ bool LockEndpoint::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & u
user.createdBy = userInDb.createdBy;
user.lastModifiedBy = userInDb.lastModifiedBy;

ChipLogDetail(
Zcl,
"Found occupied user "
"[endpoint=%d,adjustedIndex=%hu,name=\"%*.s\",credentialsCount=%zu,uniqueId=%x,type=%" PRIu8 ",credentialRule=%" PRIu8 ","
"createdBy=%d,lastModifiedBy=%d]",
mEndpointId, adjustedUserIndex, static_cast<int>(user.userName.size()), user.userName.data(), user.credentials.size(),
user.userUniqueId, to_underlying(user.userType), to_underlying(user.credentialRule), user.createdBy, user.lastModifiedBy);
ChipLogDetail(Zcl,
"Found occupied user "
"[endpoint=%d,adjustedIndex=%hu,name=\"%*.s\",credentialsCount=%zu,uniqueId=%x,type=%u,credentialRule=%u,"
"createdBy=%d,lastModifiedBy=%d]",
mEndpointId, adjustedUserIndex, static_cast<int>(user.userName.size()), user.userName.data(),
user.credentials.size(), user.userUniqueId, to_underlying(user.userType), to_underlying(user.credentialRule),
user.createdBy, user.lastModifiedBy);

return true;
}
Expand All @@ -76,8 +76,8 @@ bool LockEndpoint::SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::
ChipLogProgress(Zcl,
"Door Lock App: LockEndpoint::SetUser "
"[endpoint=%d,userIndex=%" PRIu16 ",creator=%d,modifier=%d,userName=\"%*.s\",uniqueId=%" PRIx32
",userStatus=%" PRIu8 ",userType=%" PRIu8 ","
"credentialRule=%" PRIu8 ",credentials=%p,totalCredentials=%zu]",
",userStatus=%u,userType=%u,"
"credentialRule=%u,credentials=%p,totalCredentials=%zu]",
mEndpointId, userIndex, creator, modifier, static_cast<int>(userName.size()), userName.data(), uniqueId,
to_underlying(userStatus), to_underlying(usertype), to_underlying(credentialRule), credentials,
totalCredentials);
Expand Down Expand Up @@ -132,9 +132,8 @@ bool LockEndpoint::SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::
bool LockEndpoint::GetCredential(uint16_t credentialIndex, DlCredentialType credentialType,
EmberAfPluginDoorLockCredentialInfo & credential) const
{
ChipLogProgress(
Zcl, "Door Lock App: LockEndpoint::GetCredential [endpoint=%d,credentialIndex=%" PRIu16 ",credentialType=%" PRIu8 "]",
mEndpointId, credentialIndex, to_underlying(credentialType));
ChipLogProgress(Zcl, "Door Lock App: LockEndpoint::GetCredential [endpoint=%d,credentialIndex=%" PRIu16 ",credentialType=%u]",
mEndpointId, credentialIndex, to_underlying(credentialType));

if (credentialIndex >= mLockCredentials.size() || (0 == credentialIndex && DlCredentialType::kProgrammingPIN != credentialType))
{
Expand All @@ -153,7 +152,7 @@ bool LockEndpoint::GetCredential(uint16_t credentialIndex, DlCredentialType cred
credential.credentialType = credentialInStorage.credentialType;
credential.credentialData = chip::ByteSpan(credentialInStorage.credentialData, credentialInStorage.credentialDataSize);

ChipLogDetail(Zcl, "Found occupied credential [endpoint=%d,index=%" PRIu16 ",type=%" PRIu8 ",dataSize=%zu]", mEndpointId,
ChipLogDetail(Zcl, "Found occupied credential [endpoint=%d,index=%" PRIu16 ",type=%u,dataSize=%zu]", mEndpointId,
credentialIndex, to_underlying(credential.credentialType), credential.credentialData.size());

return true;
Expand All @@ -162,11 +161,11 @@ bool LockEndpoint::GetCredential(uint16_t credentialIndex, DlCredentialType cred
bool LockEndpoint::SetCredential(uint16_t credentialIndex, DlCredentialStatus credentialStatus, DlCredentialType credentialType,
const chip::ByteSpan & credentialData)
{
ChipLogProgress(
Zcl,
"Door Lock App: LockEndpoint::SetCredential "
"[endpoint=%d,credentialIndex=%" PRIu16 ",credentialStatus=%" PRIu8 ",credentialType=%" PRIu8 ",credentialDataSize=%zu]",
mEndpointId, credentialIndex, to_underlying(credentialStatus), to_underlying(credentialType), credentialData.size());
ChipLogProgress(Zcl,
"Door Lock App: LockEndpoint::SetCredential "
"[endpoint=%d,credentialIndex=%" PRIu16 ",credentialStatus=%u,credentialType=%u,credentialDataSize=%zu]",
mEndpointId, credentialIndex, to_underlying(credentialStatus), to_underlying(credentialType),
credentialData.size());

if (credentialIndex >= mLockCredentials.size() || (0 == credentialIndex && DlCredentialType::kProgrammingPIN != credentialType))
{
Expand All @@ -188,7 +187,7 @@ bool LockEndpoint::SetCredential(uint16_t credentialIndex, DlCredentialStatus cr
std::memcpy(credentialInStorage.credentialData, credentialData.data(), credentialData.size());
credentialInStorage.credentialDataSize = credentialData.size();

ChipLogProgress(Zcl, "Successfully set the credential [mEndpointId=%d,index=%d,credentialType=%" PRIu8 "]", mEndpointId,
ChipLogProgress(Zcl, "Successfully set the credential [mEndpointId=%d,index=%d,credentialType=%u]", mEndpointId,
credentialIndex, to_underlying(credentialType));

return true;
Expand Down
9 changes: 4 additions & 5 deletions examples/light-switch-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &

if (clusterId == OnOffSwitchConfiguration::Id)
{
ChipLogProgress(Zcl,
"OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16
", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
ChipLogProgress(
Zcl, "OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == Identify::Id)
{
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
}
}
Expand Down
15 changes: 6 additions & 9 deletions examples/lighting-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,29 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
}
else if (clusterId == LevelControl::Id)
{
ChipLogProgress(Zcl,
"Level Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Level Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == ColorControl::Id)
{
ChipLogProgress(Zcl,
"Color Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Color Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == OnOffSwitchConfiguration::Id)
{
ChipLogProgress(Zcl,
"OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16
", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
ChipLogProgress(
Zcl, "OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == Identify::Id)
{
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &

if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
{
ChipLogProgress(Zcl, "Cluster OnOff: attribute OnOff set to %" PRIu8, *value);
ChipLogProgress(Zcl, "Cluster OnOff: attribute OnOff set to %u", *value);
LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION,
AppEvent::kEventType_Lighting, size, value);
}
else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id)
{
ChipLogProgress(Zcl, "Cluster LevelControl: attribute CurrentLevel set to %" PRIu8, *value);
ChipLogProgress(Zcl, "Cluster LevelControl: attribute CurrentLevel set to %u", *value);
LightingMgr().InitiateAction(LightingManager::LEVEL_ACTION, AppEvent::kEventType_Lighting, size, value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,6 @@ void AppTask::UpdateClusterState(void)
(uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status);
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
}
}
13 changes: 5 additions & 8 deletions examples/lighting-app/nxp/k32w/k32w0/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,23 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
}
else if (path.mClusterId == LevelControl::Id)
{
ChipLogProgress(Zcl,
"Level Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Level Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(path.mAttributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (path.mClusterId == ColorControl::Id)
{
ChipLogProgress(Zcl,
"Color Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Color Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(path.mAttributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (path.mClusterId == OnOffSwitchConfiguration::Id)
{
ChipLogProgress(Zcl,
"OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16
", length %" PRIu16,
ChipLogValueMEI(path.mAttributeId), type, *value, size);
ChipLogProgress(
Zcl, "OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(path.mAttributeId), type, *value, size);

// WIP Apply attribute change to Light
}
Expand Down
15 changes: 6 additions & 9 deletions examples/lighting-app/p6/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,29 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
}
else if (clusterId == LevelControl::Id)
{
ChipLogProgress(Zcl,
"Level Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Level Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == ColorControl::Id)
{
ChipLogProgress(Zcl,
"Color Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Color Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == OnOffSwitchConfiguration::Id)
{
ChipLogProgress(Zcl,
"OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16
", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
ChipLogProgress(
Zcl, "OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == Identify::Id)
{
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void AppTask::UpdateClusterState(void)
(uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status);
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
}

newValue = LightingMgr().GetLevel();
Expand All @@ -468,6 +468,6 @@ void AppTask::UpdateClusterState(void)

if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating level %" PRIx8, status);
ChipLogError(NotSpecified, "ERR: updating level %x", status);
}
}
2 changes: 1 addition & 1 deletion examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,6 @@ void AppTask::UpdateClusterState(void)
(uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status);
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
}
}
2 changes: 1 addition & 1 deletion examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,6 @@ void AppTask::UpdateClusterState(void)
(uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status);
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ota {
void DefaultUserConsentProvider::LogUserConsentSubject(const UserConsentSubject & subject)
{
ChipLogDetail(SoftwareUpdate, "User consent request for:");
ChipLogDetail(SoftwareUpdate, ": FabricIndex: %" PRIu8, subject.fabricIndex);
ChipLogDetail(SoftwareUpdate, ": FabricIndex: %u", subject.fabricIndex);
ChipLogDetail(SoftwareUpdate, ": RequestorNodeId: " ChipLogFormatX64, ChipLogValueX64(subject.requestorNodeId));
ChipLogDetail(SoftwareUpdate, ": ProviderEndpointId: %" PRIu16, subject.providerEndpointId);
ChipLogDetail(SoftwareUpdate, ": RequestorVendorId: %" PRIu16, subject.requestorVendorId);
Expand Down
15 changes: 6 additions & 9 deletions examples/ota-requestor-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,29 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
}
else if (clusterId == LevelControl::Id)
{
ChipLogProgress(Zcl,
"Level Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Level Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == ColorControl::Id)
{
ChipLogProgress(Zcl,
"Color Control attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Color Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == OnOffSwitchConfiguration::Id)
{
ChipLogProgress(Zcl,
"OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16
", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
ChipLogProgress(
Zcl, "OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);

// WIP Apply attribute change to Light
}
else if (clusterId == Identify::Id)
{
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
}
}
Expand Down
Loading

0 comments on commit 8a6be2a

Please sign in to comment.