-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fix crashes caused by 'typeset -RF' #47
Conversation
f9f6db3
to
ae99888
Compare
Variables created with 'typeset -RF' were being treated as short integers, even though they are actually floating point values. As a result the following example will cause a crash: $ typeset -RF foo=1 $ test "$foo" This is fixed by checking for 'NV_DOUBLE' with 'nv_isattr', which prevents ksh from treating floating point values as short integers due to '== NV_INT16P' excluding 'NV_DOUBLE'. This bugfix was backported from ksh93v- 2013-10-10-alpha. src/cmd/ksh93/sh/array.c, src/cmd/ksh93/sh/name.c, src/cmd/ksh93/sh/nvdisc: - Avoid treating floating point values as short integers by checking for 'NV_DOUBLE' with 'nv_isattr'. src/cmd/ksh93/tests/types.sh: - Add a regression test for the 'typeset -RF' crash. The crash cannot be replicated if 'typeset -RF' sets 'foo' to zero.
ae99888
to
817aa2f
Compare
How does this fix address the following restrictions as indicated from
|
This bugfix causes the right justify option to be ignored (rather than crash the shell): $ typeset -R3F foo=32.01
$ echo $foo
32.0100000000 |
Hmm. Which precedent should we follow? Maybe they should all error out? I think giving a usage error is more logical since this combination of flags is not actually possible. But it should be preceded by an informative error message such as "incompatible options combination". Or maybe we should just fix it so they can be combined? I see no real reason why this should be impossible. On mksh (which only supports integer arithmetic) the following works fine:
The other ksh-inspired shell that supports floating point arithmetic is zsh, and it has no problem combining any of these:
Whichever we decide to do, applying the current patch seems like a good idea regardless, as it makes the code more crash-proof at no expense. |
I think having typeset being able to recreate a variable completely in one line is the correct thing to do. I should be able to do a |
Variables created with
typeset -RF
were being treated as short integers, even though they are actually floating point values. As a result the following example will cause a crash (foo
cannot be zero):This is fixed by checking for
NV_DOUBLE
withnv_isattr
, which prevents ksh from treating floating point values as short integers due to== NV_INT16P
excludingNV_DOUBLE
. This bugfix was backported from ksh93v- 2013-10-10-alpha.