Patchwork PowerPC: Avoid segfault in cpu_dump_state

login
register
mail settings
Submitter Fabien Chouteau
Date May 14, 2012, 2:46 p.m.
Message ID <1337006815-5550-1-git-send-email-chouteau@adacore.com>
Download mbox | patch
Permalink /patch/159031/
State New
Headers show

Comments

Fabien Chouteau - May 14, 2012, 2:46 p.m.
Quit if no log file is defined.

Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
---
 target-ppc/translate.c |    4 ++++
 1 file changed, 4 insertions(+)
Peter Maydell - May 14, 2012, 3:39 p.m.
On 14 May 2012 15:46, Fabien Chouteau <chouteau@adacore.com> wrote:
> Quit if no log file is defined.
>
> Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
> ---
>  target-ppc/translate.c |    4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/target-ppc/translate.c b/target-ppc/translate.c
> index cf59765..f17bd91 100644
> --- a/target-ppc/translate.c
> +++ b/target-ppc/translate.c
> @@ -9319,6 +9319,10 @@ void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf,
>
>     int i;
>
> +    if (f == NULL) {
> +        return;
> +    }
> +
>     cpu_synchronize_state(env);
>
>     cpu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "

target-ppc isn't the only one that doesn't check for a NULL f:
perhaps it would be better to say "you can't call this with a
NULL FILE*" and fix whatever is calling it in that way?

-- PMM

Patch

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index cf59765..f17bd91 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -9319,6 +9319,10 @@  void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf,
 
     int i;
 
+    if (f == NULL) {
+        return;
+    }
+
     cpu_synchronize_state(env);
 
     cpu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "