[PATCH 05/11] gdbstub/user: localise variables for reading gdb socket

Alex Bennée posted 11 patches 6 days, 15 hours ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Laurent Vivier <laurent@vivier.eu>
[PATCH 05/11] gdbstub/user: localise variables for reading gdb socket
Posted by Alex Bennée 6 days, 15 hours ago
Keep things tidy by moving the declarations to the block where they
are used.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 gdbstub/user.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/gdbstub/user.c b/gdbstub/user.c
index cc71cda3e33..c7a3ef947ed 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -198,9 +198,6 @@ void gdb_qemu_exit(int code)
 int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
                   int siginfo_len)
 {
-    char buf[256];
-    int n;
-
     if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
         return sig;
     }
@@ -246,11 +243,10 @@ int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
     gdbserver_state.state = RS_IDLE;
     gdbserver_user_state.running_state = 0;
     while (gdbserver_user_state.running_state == 0) {
-        n = read(gdbserver_user_state.fd, buf, 256);
+        char buf[256];
+        int n = read(gdbserver_user_state.fd, buf, 256);
         if (n > 0) {
-            int i;
-
-            for (i = 0; i < n; i++) {
+            for (int i = 0; i < n; i++) {
                 gdb_read_byte(buf[i]);
             }
         } else {
-- 
2.47.3


Re: [PATCH 05/11] gdbstub/user: localise variables for reading gdb socket
Posted by Richard Henderson 5 days, 22 hours ago
On 2/3/26 21:51, Alex Bennée wrote:
> Keep things tidy by moving the declarations to the block where they
> are used.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   gdbstub/user.c | 10 +++-------
>   1 file changed, 3 insertions(+), 7 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

> 
> diff --git a/gdbstub/user.c b/gdbstub/user.c
> index cc71cda3e33..c7a3ef947ed 100644
> --- a/gdbstub/user.c
> +++ b/gdbstub/user.c
> @@ -198,9 +198,6 @@ void gdb_qemu_exit(int code)
>   int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
>                     int siginfo_len)
>   {
> -    char buf[256];
> -    int n;
> -
>       if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
>           return sig;
>       }
> @@ -246,11 +243,10 @@ int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
>       gdbserver_state.state = RS_IDLE;
>       gdbserver_user_state.running_state = 0;
>       while (gdbserver_user_state.running_state == 0) {
> -        n = read(gdbserver_user_state.fd, buf, 256);
> +        char buf[256];
> +        int n = read(gdbserver_user_state.fd, buf, 256);
>           if (n > 0) {
> -            int i;
> -
> -            for (i = 0; i < n; i++) {
> +            for (int i = 0; i < n; i++) {
>                   gdb_read_byte(buf[i]);
>               }
>           } else {