[hackers] [sbase] dc: Don't trash val next pointer || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 19 Jan 2026 18:53:54 +0100 (CET)

commit a2940adeba5293032f6ceb7d218dc9f09d6de984
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
AuthorDate: Mon Jan 19 18:49:42 2026 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
CommitDate: Mon Jan 19 18:49:42 2026 +0100

    dc: Don't trash val next pointer
    
    When a value was assigned to a register using the 's'
    command we were assigning the full value from execution
    stack, overwriting the next pointer of the register
    stack with the next pointer of the execution stack.

diff --git a/dc.c b/dc.c
index bc5f417..4f2e314 100644
--- a/dc.c
+++ b/dc.c
_AT_@ -1541,6 +1541,7 @@ dupval(Val v)
                 nv.u.n = copy(&zero);
                 break;
         }
+ nv.next = NULL;
 
         return nv;
 }
_AT_@ -2057,9 +2058,10 @@ eval(void)
                 break;
         case 's':
                 rp = lookup(regname());
+ v1 = pop();
                 freeval(rp->val);
- rp->val.type = NVAL;
- rp->val = pop();
+ rp->val.u = v1.u;
+ rp->val.type = v1.type;
                 break;
         case 'l':
                 rp = lookup(regname());
diff --git a/tests/0048-dc.sh b/tests/0048-dc.sh
new file mode 100755
index 0000000..18abd2d
--- /dev/null
+++ b/tests/0048-dc.sh
_AT_@ -0,0 +1,18 @@
+#!/bin/sh
+
+tmp=$$.tmp
+
+trap 'rm -f $tmp' EXIT
+trap 'exit $?' HUP INT TERM
+
+cat <<'EOF' > $tmp
+1
+EOF
+
+$EXEC ../dc -i <<'EOF' | diff -u - $tmp
+[Splp 1+dsps. 0 Lps. 1Q]s<1>
+
+1dsps.
+lpl<1>xs.
+lpps.
+EOF
Received on Mon Jan 19 2026 - 18:53:54 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 19 2026 - 19:00:35 CET