bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Getting a fatal error when pretty-printing a code which c


From: Aharon Robbins
Subject: Re: [bug-gawk] Getting a fatal error when pretty-printing a code which contains an empty else block
Date: Sun, 27 Dec 2015 21:36:22 +0200
User-agent: Heirloom mailx 12.5 6/20/10

Greetings. Re this:

> From: ziyunfei <address@hidden>
> Date: Wed, 23 Dec 2015 15:42:11 +0800
> To: address@hidden
> Subject: [bug-gawk] Getting a fatal error when pretty-printing a code which
>       contains an empty else block
>
> $ ./gawk -o- '{if(1){}else{}}???
> {
>       if (1) {
> } else {
>       }
> gawk: cmd. line:1: fatal error: internal error
> [1]    74558 abort      ./gawk -o- '{if(1){}else{}}???
>
> $ ./gawk -V
> GNU Awk 4.1.60, API: 1.2

Thank you for the excellent bug report. Here is the fix. It will
shortly appear in the Git repo.

Thanks,

Arnold
=====================================
diff --git a/awkgram.y b/awkgram.y
index 2592d13..facf309 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -4884,14 +4884,12 @@ mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, 
INSTRUCTION *true_branch,
         */
 
        INSTRUCTION *ip;
+       bool setup_else_part = true;
 
        if (false_branch == NULL) {
                false_branch = list_create(instruction(Op_no_op));
-               if (elsep != NULL) {            /* else { } */
-                       if (do_pretty_print)
-                               (void) list_prepend(false_branch, elsep);
-                       else
-                               bcfree(elsep);
+               if (elsep == NULL) {            /* else { } */
+                       setup_else_part = false;
                }
        } else {
                /* assert(elsep != NULL); */
@@ -4899,6 +4897,9 @@ mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, 
INSTRUCTION *true_branch,
                /* avoid a series of no_op's: if .. else if .. else if .. */
                if (false_branch->lasti->opcode != Op_no_op)
                        (void) list_append(false_branch, instruction(Op_no_op));
+       }
+
+       if (setup_else_part) {
                if (do_pretty_print) {
                        (void) list_prepend(false_branch, elsep);
                        false_branch->nexti->branch_end = false_branch->lasti;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]