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@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2023-10-16 16:54:11 -07:00
parent a7b1f26057
commit 7d5e549d63

View File

@ -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;
}