After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 773688 - division by log(1) produces segfault
division by log(1) produces segfault
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
3.16.x
Other Linux
: Normal normal
: ---
Assigned To: PioneerAxon
gcalctool maintainers
Depends on:
Blocks:
 
 
Reported: 2016-10-30 01:43 UTC by Georges Dupéron
Modified: 2017-02-13 06:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix the '(null)' error message on command-line invocations (2.44 KB, patch)
2017-01-03 17:57 UTC, PioneerAxon
committed Details | Review
Fix null 'token' in FunctionArgumentsNode (14.69 KB, patch)
2017-01-04 14:49 UTC, PioneerAxon
reviewed Details | Review

Description Georges Dupéron 2016-10-30 01:43:53 UTC
This command (and typing the same formula in the GUI) produces a segfault:

gnome-calculator -s "42/log(1)"

Interestingly, typing "log₁(42)" gives the expected division by zero error.

I am using gnome-calculator version 3.16.0 and I don't have a more recent version available to test. I did not find an existing report for this bug, but if it is already fixed in more recent versions, fell free to close this issue immediately.
Comment 1 André Klapper 2016-11-01 19:39:47 UTC
Not here:

$:andre\> gnome-calculator -s "42/log(1)"
Error: (null)
$:andre\> rpm -q gnome-calculator
gnome-calculator-3.20.2-2.fc24.x86_64
Comment 2 Robert Roth 2016-11-04 12:28:36 UTC
I can confirm that there's not segfault on 3.20.2 or later versions.
However, I don't like the fact that the GUI is telling me "Division by zero is undefined" and the command-line tool "Error: (null)". The command line error message should be improved, so I will keep this issue open to do that.

@Georges Duperon: could you please try a later version of gnome-calculator?
Comment 3 Georges Dupéron 2016-11-04 13:49:36 UTC
I tested with 3.10.3 on a Unbuntu 14.04 VM, and it prints `Error: Division by zero is undefined`

I tested with 3.18.3 on NixOs 16.03, and it still gives a segfault

I tested with 3.18.3 on a Ubuntu 16.04 Docker machine, and it prints `Error: (null)` (I couldn't test the GUI)

I tested with 3.22.0 on a Ubuntu 16.10 Docker machine, and it prints `Error: (null)` (I couldn't test the GUI)


It therefore seems to me that the issue is related to the compliation flags or dependencies used by the NixOs version, or otherwise that the issue was fixed early via Ubuntu-specific patches. Here are the two build recipies for the NixOs version:

https://github.com/NixOS/nixpkgs/blob/release-16.03/pkgs/desktops/gnome-3/3.18/core/gnome-calculator/default.nix
https://github.com/NixOS/nixpkgs/blob/release-16.03/pkgs/desktops/gnome-3/3.18/core/gnome-calculator/src.nix

The only compilation flag I see is this one (path elided with ....):

-I..../include/gio-unix-2.0

The build recipe does not seem to apply any distribution-specific patches.
Comment 4 PioneerAxon 2017-01-03 17:54:06 UTC
Georges, thanks for the bug report.

There are 2 different issues here.
1. Segfault, I debugged it and it still exists. But is hidden due to compiler optimizations, as we don't use the field being passed anywhere.
2. Error message showing "(null)" instead of real error.

I'll upload the patch for issue-2 shortly.
Issue-1 is a relatively larger change and will need some more time for testing.
Comment 5 PioneerAxon 2017-01-03 17:57:41 UTC
Created attachment 342784 [details] [review]
Fix the '(null)' error message on command-line invocations
Comment 6 Robert Roth 2017-01-03 22:40:53 UTC
Comment on attachment 342784 [details] [review]
Fix the '(null)' error message on command-line invocations

Thanks, the patch improves the situation indeed, pushing.
Comment 7 PioneerAxon 2017-01-04 14:47:01 UTC
The second patch is almost ready. I'll upload it soon.

The patch fixes the possible SEGV along with the missing highlight on some error cases.

To test the highlight part on GUI, try "42/log(1)".
Without the fix, it will print out error but won't select any part of expression.
With the fix, it'll print out error and select "log(1)", which generated the divide by zero error.

Same can be verified with "sin⁻¹2".
With the fix, it'll select "2" and print error for the domain of "sin⁻¹" function.
Comment 8 PioneerAxon 2017-01-04 14:49:48 UTC
Created attachment 342848 [details] [review]
Fix null 'token' in FunctionArgumentsNode
Comment 9 Robert Roth 2017-02-06 18:27:27 UTC
Review of attachment 342848 [details] [review]:

Nice patch, thanks. It indeed fixes error handling in the GUI and highlights the problematic token, which is an improvement indeed. I'm thinking of accepting it as is, but bonus points would go if you could also improve the command-line error handling a bit, as we still get "Error: (null)" in the command-line interface for the 42/log(1) usecase, even if the GUI perfectly handles the division by zero and highlights the problematic token.
Comment 10 PioneerAxon 2017-02-13 06:41:09 UTC
Thanks Robert.

In my local repository the error reporting works.
[pioneeraxon@gnome src]$ ./gcalccmd 
> 42/log(1)
Error Division by zero is undefined

There are 2 local changes in my repository that are not yet merged in the repository.
One of them is the patch I uploaded above, and the other is the one I uploaded in bug 775789. (link : https://bugzilla.gnome.org/attachment.cgi?id=342865&action=diff)

I forgot the reason why I had split the changes in 2 parts. But I think the other patch fixes all the generic issues of passing the error string vs. error token throughout the code.

I think once you cherry-pick both changes, it'll start working.
Comment 11 Robert Roth 2017-02-13 06:54:40 UTC
Indeed, pushing this change after the other one solved the issue too. Thanks for the reminder.
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.