Skip to content

Commit

Permalink
Log lengths of strings in payload logging. (#20934)
Browse files Browse the repository at this point in the history
Logs lengths of UTF-8 strings in chars and octet strings in bytes.
  • Loading branch information
bzbarsky-apple authored Jul 19, 2022
1 parent 612714f commit a488d9a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app/MessageDef/MessageDefHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,19 @@ CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLa
case TLV::kTLVType_UTF8String: {
char value_s[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];

#if CHIP_DETAIL_LOGGING
uint32_t readerLen = aReader.GetLength();
#endif // CHIP_DETAIL_LOGGING
CHIP_ERROR err = aReader.GetString(value_s, sizeof(value_s));
VerifyOrReturnError(err == CHIP_NO_ERROR || err == CHIP_ERROR_BUFFER_TOO_SMALL, err);

if (err == CHIP_ERROR_BUFFER_TOO_SMALL)
{
PRETTY_PRINT_SAMELINE("... (byte string too long) ...");
PRETTY_PRINT_SAMELINE("... (char string too long: %" PRIu32 " chars) ...", readerLen);
}
else
{
PRETTY_PRINT_SAMELINE("\"%s\", ", value_s);
PRETTY_PRINT_SAMELINE("\"%s\" (%" PRIu32 " chars), ", value_s, readerLen);
}
break;
}
Expand Down Expand Up @@ -218,7 +221,7 @@ CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLa
}
}

PRETTY_PRINT("]");
PRETTY_PRINT("] (%" PRIu32 " bytes)", readerLen);
break;
}

Expand Down

0 comments on commit a488d9a

Please sign in to comment.