Skip to content

Commit b2298b5

Browse files
committed
Remove TODO in AudioOutputManager
And fix potential memory violation due to memcpy
1 parent 32313e4 commit b2298b5

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

examples/chef/common/clusters/audio-output/AudioOutputManager.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ uint8_t AudioOutputManager::HandleGetCurrentOutput()
4646

4747
CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEncoder)
4848
{
49-
// TODO: Insert code here
5049
return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR {
5150
for (auto const & outputInfo : this->mOutputs)
5251
{
@@ -58,16 +57,16 @@ CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEnco
5857

5958
bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name)
6059
{
61-
// TODO: Insert code here
6260
bool audioOutputRenamed = false;
6361

6462
for (OutputInfoType & output : mOutputs)
6563
{
6664
if (output.index == index)
6765
{
6866
audioOutputRenamed = true;
69-
memcpy(this->Data(index), name.data(), name.size());
70-
output.name = chip::CharSpan(this->Data(index), name.size());
67+
const size_t len = std::min(mBufMax, name.size());
68+
memcpy(this->Data(index), name.data(), len);
69+
output.name = chip::CharSpan(this->Data(index), len);
7170
}
7271
}
7372

@@ -76,7 +75,6 @@ bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::C
7675

7776
bool AudioOutputManager::HandleSelectOutput(const uint8_t & index)
7877
{
79-
// TODO: Insert code here
8078
bool audioOutputSelected = false;
8179
for (OutputInfoType & output : mOutputs)
8280
{

examples/chef/common/clusters/audio-output/AudioOutputManager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ class AudioOutputManager : public AudioOutputDelegate
4040
uint8_t mCurrentOutput;
4141
std::vector<OutputInfoType> mOutputs;
4242
// Magic numbers are here on purpose, please allocate memory
43-
char mCharDataBuffer[10][32];
43+
static constexpr size_t mBufMax = 32;
44+
char mCharDataBuffer[10][mBufMax];
4445
};

0 commit comments

Comments
 (0)