Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add negative-zero.c test to document ksh bug #73

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

laurenthuberdeau
Copy link
Collaborator

Context

While working on #64, I tried running the compile the tests using pnut.sh (instead of pnut-sh compiled by gcc as it is usually done) and found that pnut.sh would compile the tests/_all/preprocessor/if/if.c test differently. Code guarded by a #elif block was not included because the flag we used to check if a previous condition was true was -0 and the code compared it to 0 using string comparison (as an optimization) which are obviously different.

This PR adds a test so we can track this bug.

This simple script also shows the bug:

a=0
: $(( b = -a ))
: $(( c = +a ))
echo $a # print 0
echo $b # print -0 instead of 0
echo $a # print 0 as expected

I have only been able to reproduce the issue when using ksh on ARM. Other shells and ksh in a x86 VM show the expected behavior. This is similar to this issue found by @leo-ard where an undefined behavior in ksh produced different results in the x86 and ARM versions, and it may be indirectly caused by the use of floating point numbers to do all arithmetic in ksh.

Ksh version:

$ ksh --version
  version         sh (AT&T Research) 93u+ 2012-08-01

@laurenthuberdeau laurenthuberdeau merged commit f2cfde5 into main Aug 31, 2024
26 checks passed
@laurenthuberdeau laurenthuberdeau deleted the laurent/ksh-negative-0-bug branch August 31, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant