summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Cutts <hcutts@chromium.org>2019-05-21 17:09:08 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-05-23 02:14:40 -0700
commit0ddb4813fcb6a0caf8d9248de15c2bd3d797e277 (patch)
tree2266ae462dcbe9be2ae927fea95088a55f8ab12e
parent43f4771fd02723592f99ed093db27f4ba67d24ed (diff)
downloadchrome-ec-0ddb4813fcb6a0caf8d9248de15c2bd3d797e277.tar.gz
console: improve command name length error message
I ran into this today and found the "size of array 'field' is negative" somewhat difficult to understand. Using `_Static_assert` allows us to specify a nice error message. BRANCH=none BUG=none TEST=add a command called `antidisestablishmentarianism` and run `make` Change-Id: I965f57854a87ea4923b5d0b3b02b1f89c080b7e8 Signed-off-by: Harry Cutts <hcutts@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1623372 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--include/console.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/include/console.h b/include/console.h
index 57a190226b..0b4b4c8b47 100644
--- a/include/console.h
+++ b/include/console.h
@@ -119,8 +119,9 @@ void console_has_input(void);
* Register a console command handler.
*
* @param name Command name; must not be the beginning of another
- * existing command name. Note this is NOT in quotes
- * so it can be concatenated to form a struct name.
+ * existing command name. Must be less than 15 characters
+ * long (excluding null terminator). Note this is NOT in
+ * quotes so it can be concatenated to form a struct name.
* @param routine Command handling routine, of the form
* int handler(int argc, char **argv)
* @param argdesc String describing arguments to command; NULL if none.
@@ -156,8 +157,8 @@ void console_has_input(void);
/* This macro takes all possible args and discards the ones we don't use */
#define _DCL_CON_CMD_ALL(NAME, ROUTINE, ARGDESC, HELP, FLAGS) \
static const char __con_cmd_label_##NAME[] = #NAME; \
- struct size_check##NAME { \
- int field[2 * (sizeof(__con_cmd_label_##NAME) < 16) - 1]; }; \
+ _Static_assert(sizeof(__con_cmd_label_##NAME) < 16, \
+ "command name '" #NAME "' is too long"); \
const struct console_command __keep __no_sanitize_address \
__con_cmd_##NAME \
__attribute__((section(".rodata.cmds." #NAME))) = \