* [Qemu-trivial] [PATCH] util/readline: Add braces to fix checkpatch errors
@ 2019-03-30 11:21 Jules Irenge
2019-04-01 9:09 ` [Qemu-trivial] [Qemu-devel] " Stefan Hajnoczi
2019-04-03 12:01 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Jules Irenge @ 2019-03-30 11:21 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Add braces to fix errors issued by checkpatch.pl tool
"ERROR: braces {} are necessary for all arms of this statement"
Within "util/readline.c" file
---
util/readline.c | 50 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 17 deletions(-)
diff --git a/util/readline.c b/util/readline.c
index 3eb5a66dfc..a7672b51c1 100644
--- a/util/readline.c
+++ b/util/readline.c
@@ -54,8 +54,9 @@ static void readline_update(ReadLineState *rs)
rs->cmd_buf[rs->cmd_buf_size] = '\0';
if (rs->read_password) {
len = strlen(rs->cmd_buf);
- for (i = 0; i < len; i++)
+ for (i = 0; i < len; i++) {
rs->printf_func(rs->opaque, "*");
+ }
} else {
rs->printf_func(rs->opaque, "%s", rs->cmd_buf);
}
@@ -178,13 +179,15 @@ static void readline_up_char(ReadLineState *rs)
{
int idx;
- if (rs->hist_entry == 0)
+ if (rs->hist_entry == 0) {
return;
+ }
if (rs->hist_entry == -1) {
/* Find latest entry */
for (idx = 0; idx < READLINE_MAX_CMDS; idx++) {
- if (rs->history[idx] == NULL)
+ if (rs->history[idx] == NULL) {
break;
+ }
}
rs->hist_entry = idx;
}
@@ -198,8 +201,9 @@ static void readline_up_char(ReadLineState *rs)
static void readline_down_char(ReadLineState *rs)
{
- if (rs->hist_entry == -1)
+ if (rs->hist_entry == -1) {
return;
+ }
if (rs->hist_entry < READLINE_MAX_CMDS - 1 &&
rs->history[++rs->hist_entry] != NULL) {
pstrcpy(rs->cmd_buf, sizeof(rs->cmd_buf),
@@ -216,8 +220,9 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
char *hist_entry, *new_entry;
int idx;
- if (cmdline[0] == '\0')
+ if (cmdline[0] == '\0') {
return;
+ }
new_entry = NULL;
if (rs->hist_entry != -1) {
/* We were editing an existing history entry: replace it */
@@ -230,8 +235,9 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
/* Search cmdline in history buffers */
for (idx = 0; idx < READLINE_MAX_CMDS; idx++) {
hist_entry = rs->history[idx];
- if (hist_entry == NULL)
+ if (hist_entry == NULL) {
break;
+ }
if (strcmp(hist_entry, cmdline) == 0) {
same_entry:
new_entry = hist_entry;
@@ -240,8 +246,9 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
(READLINE_MAX_CMDS - (idx + 1)) * sizeof(char *));
rs->history[READLINE_MAX_CMDS - 1] = NULL;
for (; idx < READLINE_MAX_CMDS; idx++) {
- if (rs->history[idx] == NULL)
+ if (rs->history[idx] == NULL) {
break;
+ }
}
break;
}
@@ -254,8 +261,9 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
rs->history[READLINE_MAX_CMDS - 1] = NULL;
idx = READLINE_MAX_CMDS - 1;
}
- if (new_entry == NULL)
+ if (new_entry == NULL) {
new_entry = g_strdup(cmdline);
+ }
rs->history[idx] = new_entry;
rs->hist_entry = -1;
}
@@ -297,16 +305,18 @@ static void readline_completion(ReadLineState *rs)
g_free(cmdline);
/* no completion found */
- if (rs->nb_completions <= 0)
+ if (rs->nb_completions <= 0) {
return;
+ }
if (rs->nb_completions == 1) {
len = strlen(rs->completions[0]);
for (i = rs->completion_index; i < len; i++) {
readline_insert_char(rs, rs->completions[0][i]);
}
/* extra space for next argument. XXX: make it more generic */
- if (len > 0 && rs->completions[0][len - 1] != '/')
+ if (len > 0 && rs->completions[0][len - 1] != '/') {
readline_insert_char(rs, ' ');
+ }
} else {
qsort(rs->completions, rs->nb_completions, sizeof(char *),
completion_comp);
@@ -318,25 +328,29 @@ static void readline_completion(ReadLineState *rs)
if (i == 0) {
max_prefix = len;
} else {
- if (len < max_prefix)
+ if (len < max_prefix) {
max_prefix = len;
+ }
for (j = 0; j < max_prefix; j++) {
- if (rs->completions[i][j] != rs->completions[0][j])
+ if (rs->completions[i][j] != rs->completions[0][j]) {
max_prefix = j;
+ }
}
}
- if (len > max_width)
+ if (len > max_width) {
max_width = len;
+ }
}
if (max_prefix > 0)
for (i = rs->completion_index; i < max_prefix; i++) {
readline_insert_char(rs, rs->completions[0][i]);
}
max_width += 2;
- if (max_width < 10)
+ if (max_width < 10) {
max_width = 10;
- else if (max_width > 80)
+ } else if (max_width > 80) {
max_width = 80;
+ }
nb_cols = 80 / max_width;
j = 0;
for (i = 0; i < rs->nb_completions; i++) {
@@ -383,8 +397,9 @@ void readline_handle_byte(ReadLineState *rs, int ch)
case 10:
case 13:
rs->cmd_buf[rs->cmd_buf_size] = '\0';
- if (!rs->read_password)
+ if (!rs->read_password) {
readline_hist_add(rs, rs->cmd_buf);
+ }
rs->printf_func(rs->opaque, "\n");
rs->cmd_buf_index = 0;
rs->cmd_buf_size = 0;
@@ -495,8 +510,9 @@ void readline_restart(ReadLineState *rs)
const char *readline_get_history(ReadLineState *rs, unsigned int index)
{
- if (index >= READLINE_MAX_CMDS)
+ if (index >= READLINE_MAX_CMDS) {
return NULL;
+ }
return rs->history[index];
}
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-trivial] [Qemu-devel] [PATCH] util/readline: Add braces to fix checkpatch errors
2019-03-30 11:21 [Qemu-trivial] [PATCH] util/readline: Add braces to fix checkpatch errors Jules Irenge
@ 2019-04-01 9:09 ` Stefan Hajnoczi
2019-04-03 12:01 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2019-04-01 9:09 UTC (permalink / raw)
To: Jules Irenge; +Cc: qemu-devel, qemu-trivial
[-- Attachment #1: Type: text/plain, Size: 401 bytes --]
On Sat, Mar 30, 2019 at 11:21:42AM +0000, Jules Irenge wrote:
> Add braces to fix errors issued by checkpatch.pl tool
> "ERROR: braces {} are necessary for all arms of this statement"
> Within "util/readline.c" file
> ---
> util/readline.c | 50 ++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 33 insertions(+), 17 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-trivial] [Qemu-devel] [PATCH] util/readline: Add braces to fix checkpatch errors
2019-03-30 11:21 [Qemu-trivial] [PATCH] util/readline: Add braces to fix checkpatch errors Jules Irenge
2019-04-01 9:09 ` [Qemu-trivial] [Qemu-devel] " Stefan Hajnoczi
@ 2019-04-03 12:01 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2019-04-03 12:01 UTC (permalink / raw)
To: Jules Irenge; +Cc: qemu-devel, qemu-trivial
[-- Attachment #1: Type: text/plain, Size: 515 bytes --]
On Sat, Mar 30, 2019 at 11:21:42AM +0000, Jules Irenge wrote:
> Add braces to fix errors issued by checkpatch.pl tool
> "ERROR: braces {} are necessary for all arms of this statement"
> Within "util/readline.c" file
> ---
> util/readline.c | 50 ++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 33 insertions(+), 17 deletions(-)
This file is unmaintained, I'll take this patch through my tree.
Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-03 12:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-30 11:21 [Qemu-trivial] [PATCH] util/readline: Add braces to fix checkpatch errors Jules Irenge
2019-04-01 9:09 ` [Qemu-trivial] [Qemu-devel] " Stefan Hajnoczi
2019-04-03 12:01 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).