SIGSEGV in dc, at bcode.c:277 (function reset_bmachine())

David Wolfskill david at
Sun Apr 11 00:14:55 UTC 2010

As these things go, this probably isn't as critical as most thinsg
disussed on this list, but I happened to notice it today, built a
debugging world and at least cornered the annoying little varmint.

Sorry; no patch at this time. :-(

Here's how to reproduce it: while running CURRENT, invoke dc(1)
using the command-line expression-soecification ("-e ..."), thus:

freebeast(9.0-C)[2] dc -e "6 2/p"
Segmentation fault (core dumped)

This was running:

FreeBSD 9.0-CURRENT FreeBSD 9.0-CURRENT #1 r206447: Sat Apr 10 14:49:56 PDT 2010     root at  i386

It's been a while since I did much with gdb, so the attempt at
post-mortem dump analysis wasn't very useful.

However, I did try re-running the test under gdb, which demonstrated
that on (initial) entry to reset_bmachine(), init_bmachine() has
not (yet?) been called; as as result, there is no storage allocated
to bmachine.readstack[].

This is an issue because reset_bmachine() tries to place data in
that array, thus:

    271 /* Reset the things needed before processing a (new) file */
    272 void
    273 reset_bmachine(struct source *src)
    274 {
    276         bmachine.readsp = 0;
    277         bmachine.readstack[0] = *src;
    278 }

Now, I've not had occasion to prowl around and become familiar with
the internals of dc(1), so I don't know whether invoking reset_bmachine()
without having invoked init_bmachine() beforehand is just bogus, or if
perhaps reset_bmachine() should check to see if init_bmachine() has been
called (and if not, call it), or ....

But I think it's fairly clear that there's a bit of a logic error here.

[In case anyone was wondering why someone might try to use that form
of invocation: I was doing arithmetic in a shell script, and wanted
to be able to control rounding, rather than necessarily performing so-
called "integer" arithmetic.]

I can file a PR if it would help the tracking & getting the bug fixed.

David H. Wolfskill				david at
Depriving a girl or boy of an opportunity for education is evil.

See for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url :

More information about the freebsd-current mailing list