https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=290423

            Bug ID: 290423
           Summary: /usr/bin/dc broken?
           Product: Base System
           Version: 13.5-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: [email protected]
          Reporter: [email protected]

I use dc extensively both interactively and in scripts, but it appears to have
changed behavior and dumps core as well.

Add bunch of numbers:

  dc
  16 k
  15.4
  30.8
  15.4
  3.99
  19.25
  21.49
  + p
  40.74
  + p
  44.73
  + p
  60.13
  + p
  90.93
  + p
  106.33
  + p

  Runtime error: stack has too few elements
      0: (main)

  p
  zsh: segmentation fault (core dumped)  dc

This seems to happen for any such input which has one or more extra "+": 


  dc
  1 2 ++ p

  Runtime error: stack has too few elements
      0: (main)

  p
  zsh: segmentation fault (core dumped)  dc

I does work if there are correct number of operations (+ in this case, but it
seems to be not specific to +, * also does this). But the behaviour has changed
in a way which may break scripts and remove useful usage:

- Previously, when, say, you did too many operations, such as putting in 3
number and then used +++, it say stack empty and top of the stack included the
value of the last successful operation. 

- Now the error message has changed, and when using "p" to print top of the
stack, it dumps core instead of printing top of the stack.

- It seems that output is not flushed at all when this error message happens.
The output file is empty (I tried both pipe and output to file). I have not
tested is this is different from previous behavior.

- If all the input is on the same line, "p" is ignored after error, and doing 
"p" separately will cause the core dump. So, error also causes input to be
eaten without action. So, when testing this, it will only dump core after error
message if "p" is inserted separately. This is different from earlier behavior. 

I noticed this as when using interactively, it was useful to be able to use
more operations than what is in the stack, as I could paste bunch of numbers
into dc and then just throw some ++++++ after that to add them up, got an error
message but the calculation was still done correctly. While I can see this
might not be pedantic enough, it was nonetheless useful feature, and and made
dc robust against simple mistakes in scripts or intentional use of previous
behavior.

This should be fixed:

1. Calculation is done, error messages should not change results of successful
operations.

2. Stack sould be what was there before erroneous operation. I do not know if
this is the case as it currently dumps core when printing.

3. Do not dump core when printing top of the stack in any case.

4. Do not eat commands from input stack empty error happens.

5. This should depend on what exactly was the earlier behavior, as dc is really
core utility used by scripts and people's reflexes and should be backwards
compatible. If behavior is changed, either command name change or separate
option/environment variable for strict error handling would be better. 

I do not have earlier versions of FreeBSD online so I cannot test, but dc on
debian linux seems to work as before:

debian linux:
  dc
  1 2 ++ p
  dc: stack empty
  3

No core dump and "p" is executed.

I do not know at what point this change happened. Both 13.5 and 14.3 have this
bug.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to