[nasm:nasm-2.16.xx] asm/rdstrnum: always handle 64 bits
nasm-bot for H. Peter Anvin
hpa at zytor.com
Mon Oct 16 16:57:04 PDT 2023
Commit-ID: 7d5e549d6385ffef050d830317d7663e88d2986e
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=7d5e549d6385ffef050d830317d7663e88d2986e
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 16 Oct 2023 16:54:11 -0700
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 16 Oct 2023 16:54:11 -0700
asm/rdstrnum: always handle 64 bits
We should always support up to 8 characters, i.e. 64 bits, in a
string-to-numeric conversion.
Reported-by: Aleksandras Krupica <vaikutisasa at gmail.com>
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
asm/rdstrnum.c | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/asm/rdstrnum.c b/asm/rdstrnum.c
index 319f140a..5c8edc59 100644
--- a/asm/rdstrnum.c
+++ b/asm/rdstrnum.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2016 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -49,22 +49,13 @@ int64_t readstrnum(char *str, int length, bool *warn)
int i;
*warn = false;
-
- str += length;
- if (globalbits == 64) {
- for (i = 0; i < length; i++) {
- if (charconst & UINT64_C(0xFF00000000000000))
- *warn = true;
- charconst &= ~UINT64_C(0xFF00000000000000);
- charconst = (charconst << 8) + (uint8_t)*--str;
- }
- } else {
- for (i = 0; i < length; i++) {
- if (charconst & UINT32_C(0xFF000000))
- *warn = true;
- charconst &= ~UINT32_C(0xFF000000);
- charconst = (charconst << 8) + (uint8_t)*--str;
- }
+ if (length > 8) {
+ *warn = true;
+ length = 8;
}
+
+ for (i = 0; i < length; i++)
+ charconst += (uint64_t)((uint8_t)(*str++)) << (i*8);
+
return charconst;
}
More information about the Nasm-commits
mailing list