diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2021-03-11 13:17:35 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-21 19:18:34 +0000 |
commit | 372cb73ad00c9c928501a2155ac6c6c8f25ab290 (patch) | |
tree | 2ee70a6f1a1b749a0b2fba98553be1d5daaccd65 | |
parent | 2a2b10cfc9c22737f4c02fa976caef3c40317847 (diff) | |
download | chrome-ec-372cb73ad00c9c928501a2155ac6c6c8f25ab290.tar.gz |
ectool: Fix array size check for pchg_state_text
This patch fixes the runtime check for pchg_state_text size and adds
BUILD_ASSERT.
BUG=b:182600604, b:173235954
BRANCH=none
TEST=Verify 'ectool pchg 0' prints states properly on CoachZ.
Change-Id: Id6c6bfb979dbb4f11b1ee3dcaa0b7dc0710dfc54
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2970902
-rw-r--r-- | util/ectool.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/util/ectool.c b/util/ectool.c index 8d91d2cb74..7a03764508 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -9402,7 +9402,9 @@ static int cmd_pchg_info(const struct ec_response_pchg *res) { static const char * const pchg_state_text[] = EC_PCHG_STATE_TEXT; - printf("State: %s (%d)\n", res->state < sizeof(pchg_state_text) + BUILD_ASSERT(ARRAY_SIZE(pchg_state_text) == PCHG_STATE_COUNT); + + printf("State: %s (%d)\n", res->state < PCHG_STATE_COUNT ? pchg_state_text[res->state] : "UNDEF", res->state); printf("Battery: %u%%\n", res->battery_percentage); printf("Errors: 0x%x\n", res->error); |