diff options
author | Björn Gustavsson <[email protected]> | 2016-02-22 07:17:29 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-02-25 10:27:58 +0100 |
commit | 0d73923519dc9972a1cf31a5927692f51dbd7d8b (patch) | |
tree | 46dac92b89ada65857601c2619c61c1c025302c4 /lib/ssl/src/ssl_sup.erl | |
parent | b9f0b1259da6a26982855f490ba31a0031fca247 (diff) | |
download | otp-0d73923519dc9972a1cf31a5927692f51dbd7d8b.tar.gz otp-0d73923519dc9972a1cf31a5927692f51dbd7d8b.tar.bz2 otp-0d73923519dc9972a1cf31a5927692f51dbd7d8b.zip |
Produce warnings for binary patterns that will never match
Binary matching can be confusing. For example:
1> <<-1>> = <<-1>>.
** exception error: no match of right hand side value <<"ÿ">>
2>
When constructing binaries, the value will be masked to fit in
the binary segment. But no such masking happens when matching
binaries.
One solution that we considered was to do the same masking when
matching. We have rejected that solution for several reasons:
* Masking in construction is highly controversial and by some
people considered a bad design decision.
* While masking of unsigned numbers can be understood, masking of
signed numbers it not easy to understand.
* Then there is the question of backward compatibility. Adding
masking to matching would mean that clauses that did not match
earlier would start to match. That means that code that has
never been tested will be executed. Code that has not been
tested will usually not work.
Therefore, we have decided to warn for binary patterns that cannot
possibly match.
While we are it, we will also warn for the following example where
size for a binary segment is invalid:
bad_size(Bin) ->
BadSize = bad_size,
<<42:BadSize>> = Bin.
That example would crash the HiPE compiler because the BEAM compiler
would generate a bs_get_integer2 instruction with an invalid size
field. We can avoid that crash if sys_core_fold not only warns for bad
binary pattern, but also removes the clauses that will not match.
Reported-by: http://bugs.erlang.org/browse/ERL-44
Reported-by: Kostis Sagonas
Diffstat (limited to 'lib/ssl/src/ssl_sup.erl')
0 files changed, 0 insertions, 0 deletions