When we have an exact limb switch, we may end up with a case where the
value no longer has any remaining valid bits. In that case, we end up
relying on the expression *mp |= v << ms shifting the bits on the
subsequent limb all the way to zero, but that is not how real hardware
works when the shift count equals the width of the type. This is
undefined behavior and does, in fact, produce the wrong result.
Instead, change the test for limb shift to (ms < 0), meaning that we
defer the advance to the next limb until we actually need it. At that
point, change the shift into the *old* limb to have a cast to
(fp_2limb) which means the shift right of LIMB_BITS is valid and
produces a zero value as expected.
Reported-by: Brooks Moses <bmoses@google.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The input file is provided by nasm_error(), we should not include it
in the printf list (compiler warning + wrong message.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
External symbols are defined via deflabel(), but deflabel() is not
called until pass0 == 1. Until that happens, segbase has no way to
know what the proper segment base of the segment actually is.
Thus, testing for pass0 == 0 will always fail for a forward reference;
correct the test to test for pass0 < 2, i.e. the assert should fail
only for the final code-generation pass.
Reported-by: <stsp@list.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
When we are running regression tests we compare binary
forms and the strings better to be the constants to not
trigger false positives.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
If no output filename is specified, then a default filename is used
based on the input filename. If that ends up the *same* as the input
filename, change the output filename to "nasm.out".
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
readnum returns 64bit number which may become
a negative integer upon conversion which in
turn lead to out of bound array access.
Fix it by explicit conversion with bounds check
| POC6:2: error: parameter count `2222222222' is out of bounds [0; 2147483647]
https://bugzilla.nasm.us/show_bug.cgi?id=3392528
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm-2.14.xx:
preproc: command-line preproc directive after system-generated
gorcunov@: Had to fix include_path StrList conversion,
it is a bit ugly by now, will rework.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* commit '9a1216a1efa0ccb48e5df97acc763ea3de71e0ce':
NASM 2.14
nasmdoc.src: fix compound word
doc: Add a description for a useful case of mangling symbols
preproc: Don't access out of bound data on malformed input
rdstrnum: Make sure we dont shift out of bound
preproc: Fix out of bound access on malformed input
doc: Clarify %include search directory semantics
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
BR 3392527: make sure that all command-line specified preprocessing
directives are processed after the system-generated ones. In
particular __OUTPUT_FORMAT__ was generated after command line pass 2,
at which point -p, -d, -u, --pragma and --before had already been
processed.
There is no reason to split up defined_macros() anymore: the right
place to execute it is simply between command line passes 1 and 2. We
can also set dfmt here, which lets us define a __DEBUG_FORMAT__ macro
as well.
Finally move some options that have no business being processed in
pass 2 to pass 1.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>