shell: Make shell_strlen return u16_t
Everywhere the return of this function was being assigned to u16_t to save space on stack. Instead of casting in all these places (and may end up with overflow), just changing this function's return. Note that the function itself is not checking for overflow yet since I'm not sure this can happen and/or is a problem. Though now we have only one single point to fix this problem. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
bc4cb76df5
commit
80c03550ba
4 changed files with 13 additions and 12 deletions
|
@ -167,7 +167,7 @@ static void history_put(const struct shell *shell, u8_t *line, size_t length)
|
|||
static void history_handle(const struct shell *shell, bool up)
|
||||
{
|
||||
bool history_mode;
|
||||
size_t len;
|
||||
u16_t len;
|
||||
|
||||
/*optional feature */
|
||||
if (!IS_ENABLED(CONFIG_SHELL_HISTORY)) {
|
||||
|
@ -380,8 +380,8 @@ static void autocomplete(const struct shell *shell,
|
|||
size_t subcmd_idx)
|
||||
{
|
||||
const struct shell_static_entry *match;
|
||||
size_t arg_len = shell_strlen(arg);
|
||||
size_t cmd_len;
|
||||
u16_t cmd_len;
|
||||
u16_t arg_len = shell_strlen(arg);
|
||||
|
||||
/* shell->ctx->active_cmd can be safely used outside of command context
|
||||
* to save stack
|
||||
|
@ -510,11 +510,10 @@ static void partial_autocomplete(const struct shell *shell,
|
|||
const char *arg,
|
||||
size_t first, size_t cnt)
|
||||
{
|
||||
size_t arg_len = shell_strlen(arg);
|
||||
const char *completion;
|
||||
u16_t common;
|
||||
|
||||
common = common_beginning_find(cmd, &completion, first, cnt, arg_len);
|
||||
u16_t arg_len = shell_strlen(arg);
|
||||
u16_t common = common_beginning_find(cmd, &completion,
|
||||
first, cnt, arg_len);
|
||||
|
||||
if (common) {
|
||||
shell_op_completion_insert(shell, &completion[arg_len],
|
||||
|
@ -1404,10 +1403,12 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
|
|||
|
||||
int shell_prompt_change(const struct shell *shell, char *prompt)
|
||||
{
|
||||
u16_t len;
|
||||
|
||||
__ASSERT_NO_MSG(shell);
|
||||
__ASSERT_NO_MSG(prompt);
|
||||
|
||||
size_t len = shell_strlen(prompt);
|
||||
len = shell_strlen(prompt);
|
||||
|
||||
if (len <= CONFIG_SHELL_PROMPT_LENGTH) {
|
||||
memcpy(shell->prompt, prompt, len + 1); /* +1 for '\0' */
|
||||
|
|
|
@ -197,8 +197,8 @@ char shell_make_argv(size_t *argc, char **argv, char *cmd, u8_t max_argc)
|
|||
void shell_pattern_remove(char *buff, u16_t *buff_len, const char *pattern)
|
||||
{
|
||||
char *pattern_addr = strstr(buff, pattern);
|
||||
u16_t shift;
|
||||
u16_t pattern_len = shell_strlen(pattern);
|
||||
size_t shift;
|
||||
|
||||
if (!pattern_addr) {
|
||||
return;
|
||||
|
|
|
@ -31,9 +31,9 @@ s32_t column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons,
|
|||
void shell_multiline_data_calc(struct shell_multiline_cons *cons,
|
||||
u16_t buff_pos, u16_t buff_len);
|
||||
|
||||
static inline size_t shell_strlen(const char *str)
|
||||
static inline u16_t shell_strlen(const char *str)
|
||||
{
|
||||
return str == NULL ? 0 : strlen(str);
|
||||
return str == NULL ? 0U : (u16_t)strlen(str);
|
||||
}
|
||||
|
||||
char shell_make_argv(size_t *argc, char **argv, char *cmd, uint8_t max_argc);
|
||||
|
|
|
@ -132,7 +132,7 @@ static enum shell_wildcard_status commands_expand(const struct shell *shell,
|
|||
|
||||
bool shell_wildcard_character_exist(const char *str)
|
||||
{
|
||||
size_t str_len = shell_strlen(str);
|
||||
u16_t str_len = shell_strlen(str);
|
||||
|
||||
for (size_t i = 0; i < str_len; i++) {
|
||||
if ((str[i] == '?') || (str[i] == '*')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue