Skip to content

Commit

Permalink
[CI] Make SystemCommands take a StringBuilderBase to avoid extra stac…
Browse files Browse the repository at this point in the history
…k usage (project-chip#17984)
  • Loading branch information
carol-apple authored and pull[bot] committed May 4, 2022
1 parent 8704fb8 commit c97cd7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/app/tests/suites/commands/system/SystemCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*
*/

#include <lib/support/StringBuilder.h>

#include "SystemCommands.h"

namespace {
Expand All @@ -36,8 +34,8 @@ CHIP_ERROR SystemCommands::Start(uint16_t discriminator, uint16_t port, const ch
constexpr const char * scriptName = "Start.py";

char command[kCommandMaxLen];
ReturnErrorOnFailure(
CreateCommonCommandArgs(command, sizeof(command), scriptDir, scriptName, registerKey, discriminator, port, kvs));
chip::StringBuilderBase builder(command, sizeof(command));
ReturnErrorOnFailure(CreateCommonCommandArgs(builder, scriptDir, scriptName, registerKey, discriminator, port, kvs));
return RunInternal(command);
}

Expand Down Expand Up @@ -80,13 +78,12 @@ CHIP_ERROR SystemCommands::RunInternal(const char * command)
return ContinueOnChipMainThread(CHIP_NO_ERROR);
}

CHIP_ERROR SystemCommands::CreateCommonCommandArgs(char * commandBuffer, size_t commandBufferSize, const char * scriptDir,
CHIP_ERROR SystemCommands::CreateCommonCommandArgs(chip::StringBuilderBase & builder, const char * scriptDir,
const char * scriptName, const char * registerKey, uint16_t discriminator,
uint16_t port, const char * kvs)
{
VerifyOrReturnError(registerKey != nullptr, CHIP_ERROR_INVALID_KEY_ID);

chip::StringBuilder<kCommandMaxLen> builder;
builder.Add(scriptDir);
builder.Add(scriptName);
builder.Add(" ");
Expand All @@ -109,7 +106,6 @@ CHIP_ERROR SystemCommands::CreateCommonCommandArgs(char * commandBuffer, size_t
builder.Add(kvs);
}
VerifyOrReturnError(builder.Fit(), CHIP_ERROR_BUFFER_TOO_SMALL);
strncpy(commandBuffer, builder.c_str(), commandBufferSize);

return CHIP_NO_ERROR;
}
6 changes: 3 additions & 3 deletions src/app/tests/suites/commands/system/SystemCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <lib/support/CodeUtils.h>
#include <lib/support/StringBuilder.h>

class SystemCommands
{
Expand All @@ -36,7 +37,6 @@ class SystemCommands

private:
CHIP_ERROR RunInternal(const char * command);
CHIP_ERROR CreateCommonCommandArgs(char * commandBuffer, size_t commandBufferSize, const char * scriptDir,
const char * scriptName, const char * registerKey, uint16_t discriminator, uint16_t port,
const char * kvs);
CHIP_ERROR CreateCommonCommandArgs(chip::StringBuilderBase & builder, const char * scriptDir, const char * scriptName,
const char * registerKey, uint16_t discriminator, uint16_t port, const char * kvs);
};

0 comments on commit c97cd7f

Please sign in to comment.