URI:
       dc: prevent segfaults by cleaning up data - sbase - suckless unix tools
  HTML git clone git://git.suckless.org/sbase
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 1c79098178db0f6c26bf4459902000b81c098dd0
   DIR parent 46c00d58d59b9be55c4dcdb11605a90baa60d310
  HTML Author: Elie Le Vaillant <eolien55@disroot.org>
       Date:   Sat, 17 Jan 2026 17:00:46 +0100
       
       dc: prevent segfaults by cleaning up data
       
       Without these changes, dc can undergo segfaults in a variety of
       situations (list of cases that segfault, one for changed line):
       1. echo 'e(5)' | bc -lc | dc
       2. echo 'la sa sa sa' | dc
       3. echo '5p' > a.dc; dc a.dc
       
       Diffstat:
         M dc.c                                |       3 ++-
         A tests/0046-dc.c                     |      22 ++++++++++++++++++++++
       
       2 files changed, 24 insertions(+), 1 deletion(-)
       ---
   DIR diff --git a/dc.c b/dc.c
       @@ -1406,6 +1406,7 @@ pop(void)
                v = *stack;
                free(stack);
                stack = v.next;
       +        v.next = NULL;
        
                return v;
        }
       @@ -2057,6 +2058,7 @@ eval(void)
                case 's':
                        rp = lookup(regname());
                        freeval(rp->val);
       +                rp->val.type = NVAL;
                        rp->val = pop();
                        break;
                case 'l':
       @@ -2169,7 +2171,6 @@ dc(char *fname)
                while (moreinput())
                        eval();
        
       -        fclose(fp);
                free(input);
                input = NULL;
        }
   DIR diff --git a/tests/0046-dc.c b/tests/0046-dc.c
       @@ -0,0 +1,22 @@
       +#!/bin/sh
       +
       +set -e
       +
       +tmp1=$$.tmp1
       +tmp2=$$.tmp2
       +
       +trap 'rm -f $tmp1 $tmp2' EXIT
       +trap 'exit $?' HUP INT TERM
       +
       +cat <<EOF >$tmp1
       +../dc: stack empty
       +5
       +148.41315910257660342111
       +EOF
       +
       +echo 5p >$tmp2
       +
       +../dc $tmp2 <<EOF 2>&1 | diff -u - $tmp1
       +`echo 'e(5)' | ../bc -c ../bc.library`
       +la sa sa sa
       +EOF