Do not limit strings to 255 characters

This commit is contained in:
ISSOtm
2024-03-21 21:31:10 -04:00
committed by Sylvie
parent 9f239f6dcc
commit e255af9e10
25 changed files with 52 additions and 130 deletions

View File

@@ -186,7 +186,6 @@ _rgbasm_completions() {
empty-macro-arg
empty-strrpl
large-constant
long-string
macro-shift
nested-comment
numeric-string

View File

@@ -17,7 +17,6 @@ _rgbasm_warnings() {
'empty-macro-arg:Warn on empty macro arg'
'empty-strrpl:Warn on calling STRRPL with empty pattern'
'large-constant:Warn on constants too large for a signed 32-bit int'
'long-string:Warn on strings too long'
'macro-shift:Warn when shifting macro args part their limits'
'nested-comment:Warn on "/*" inside block comments'
'numeric-string:Warn when a multi-character string is treated as a number'

View File

@@ -13,8 +13,6 @@
#include "platform.hpp" // SSIZE_MAX
#define MAXSTRLEN 255
#define LEXER_BUF_SIZE 42 // TODO: determine a sane value for this
// The buffer needs to be large enough for the maximum `peekInternal` lookahead distance
static_assert(LEXER_BUF_SIZE > 1, "Lexer buffer size is too small");

View File

@@ -19,7 +19,6 @@ enum WarningID {
WARNING_EMPTY_MACRO_ARG, // Empty macro argument
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
WARNING_LARGE_CONSTANT, // Constants too large
WARNING_LONG_STR, // String too long for internal buffers
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
WARNING_OBSOLETE, // Obsolete things

View File

@@ -266,10 +266,6 @@ This warning is enabled by
Warn when a constant too large to fit in a signed 32-bit integer is encountered.
This warning is enabled by
.Fl Wall .
.It Fl Wlong-string
Warn when a string too long to fit in internal buffers is encountered.
This warning is enabled by
.Fl Wall .
.It Fl Wmacro-shift
Warn when shifting macro arguments past their limits.
This warning is enabled by

View File

@@ -9,7 +9,6 @@
#include <string.h>
#include "asm/fixpoint.hpp"
#include "asm/lexer.hpp" // MAXSTRLEN
#include "asm/warning.hpp"
void FormatSpec::useCharacter(int c) {
@@ -133,11 +132,6 @@ void FormatSpec::appendString(std::string &str, std::string const &value) const
str.append(padLen, ' ');
str.append(value);
}
if (str.length() > MAXSTRLEN) {
error("Formatted string value too long\n");
str.resize(MAXSTRLEN);
}
}
void FormatSpec::appendNumber(std::string &str, uint32_t value) const {
@@ -245,9 +239,4 @@ void FormatSpec::appendNumber(std::string &str, uint32_t value) const {
}
str.append(valueBuf);
}
if (str.length() > MAXSTRLEN) {
error("Formatted numeric value too long\n");
str.resize(MAXSTRLEN);
}
}

View File

@@ -1347,11 +1347,6 @@ static std::string readString(bool raw) {
}
finish:
if (yylval.length() > MAXSTRLEN) {
warning(WARNING_LONG_STR, "String constant too long\n");
yylval.resize(MAXSTRLEN);
}
lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false;
@@ -1495,11 +1490,6 @@ static void appendStringLiteral(std::string &yylval, bool raw) {
}
finish:
if (yylval.length() > MAXSTRLEN) {
warning(WARNING_LONG_STR, "String constant too long\n");
yylval.resize(MAXSTRLEN);
}
lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false;
}
@@ -1933,10 +1923,6 @@ append:
}
finish:
if (yylval.length() > MAXSTRLEN) {
warning(WARNING_LONG_STR, "Macro argument too long\n");
yylval.resize(MAXSTRLEN);
}
// Trim right whitespace
auto rightPos = std::find_if_not(yylval.rbegin(), yylval.rend(), isWhitespace);
yylval.resize(rightPos.base() - yylval.begin());

View File

@@ -1615,10 +1615,6 @@ strcat_args:
| strcat_args COMMA string {
$$ = std::move($1);
$$.append($3);
if ($$.length() > MAXSTRLEN) {
warning(WARNING_LONG_STR, "STRCAT: String too long '%s'\n", $$.c_str());
$$.resize(MAXSTRLEN);
}
}
;
@@ -2556,7 +2552,7 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
uint32_t curLen = 0;
// Compute the result length in bytes.
while (ptr[index] && index - startIndex < MAXSTRLEN && curLen < len) {
while (ptr[index] && curLen < len) {
switch (decode(&state, &codep, ptr[index])) {
case 1:
errorInvalidUTF8Byte(ptr[index], "STRSUB");
@@ -2569,7 +2565,6 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
index++;
}
// Check if `index - startIndex == MAXSTRLEN` before `curLen == len`.
if (curLen < len)
warning(WARNING_BUILTIN_ARG, "STRSUB: Length too big: %" PRIu32 "\n", len);
@@ -2641,11 +2636,6 @@ static std::string strrpl(std::string_view str, std::string const &old, std::str
str.remove_prefix(pos + old.size());
}
if (rpl.length() > MAXSTRLEN) {
warning(WARNING_LONG_STR, "STRRPL: String too long, got truncated\n");
rpl.resize(MAXSTRLEN);
}
return rpl;
}
@@ -2656,7 +2646,7 @@ static std::string strfmt(
std::string str;
size_t argIndex = 0;
for (size_t i = 0; spec[i] != '\0' && str.length() <= MAXSTRLEN; ++i) {
for (size_t i = 0; spec[i] != '\0'; ++i) {
int c = spec[i];
if (c != '%') {
@@ -2712,10 +2702,6 @@ static std::string strfmt(
argIndex
);
if (str.length() > MAXSTRLEN) {
warning(WARNING_LONG_STR, "STRFMT: String too long, got truncated\n");
str.resize(MAXSTRLEN);
}
return str;
}

View File

@@ -29,7 +29,6 @@ static const WarningState defaultWarnings[ARRAY_SIZE(warningStates)] = {
WARNING_DISABLED, // WARNING_EMPTY_MACRO_ARG
WARNING_DISABLED, // WARNING_EMPTY_STRRPL
WARNING_DISABLED, // WARNING_LARGE_CONSTANT
WARNING_DISABLED, // WARNING_LONG_STR
WARNING_DISABLED, // WARNING_MACRO_SHIFT
WARNING_ENABLED, // WARNING_NESTED_COMMENT
WARNING_ENABLED, // WARNING_OBSOLETE
@@ -77,7 +76,6 @@ static char const * const warningFlags[NB_WARNINGS] = {
"empty-macro-arg",
"empty-strrpl",
"large-constant",
"long-string",
"macro-shift",
"nested-comment",
"obsolete",
@@ -157,7 +155,6 @@ static uint8_t const _wallCommands[] = {
WARNING_EMPTY_DATA_DIRECTIVE,
WARNING_EMPTY_STRRPL,
WARNING_LARGE_CONSTANT,
WARNING_LONG_STR,
WARNING_NESTED_COMMENT,
WARNING_OBSOLETE,
WARNING_NUMERIC_STRING_1,
@@ -188,7 +185,6 @@ static uint8_t const _weverythingCommands[] = {
WARNING_EMPTY_MACRO_ARG,
WARNING_EMPTY_STRRPL,
WARNING_LARGE_CONSTANT,
WARNING_LONG_STR,
WARNING_MACRO_SHIFT,
WARNING_NESTED_COMMENT,
WARNING_OBSOLETE,

View File

@@ -1,3 +1,5 @@
; Strings used to be truncated to 255 characters with a warning.
def num equ 42
def fix equ 123.0
def str equs "hello"

View File

@@ -1,35 +1,5 @@
error: format-truncation.asm(5):
Formatted numeric value too long
error: format-truncation.asm(6):
Formatted numeric value too long
error: format-truncation.asm(7):
Fractional width 260 too long, limiting to 255
error: format-truncation.asm(7):
Formatted numeric value too long
error: format-truncation.asm(8):
Formatted string value too long
error: format-truncation.asm(9):
Formatted string value too long
error: format-truncation.asm(11):
Formatted numeric value too long
warning: format-truncation.asm(11): [-Wlong-string]
String constant too long
error: format-truncation.asm(12):
Formatted numeric value too long
warning: format-truncation.asm(12): [-Wlong-string]
String constant too long
error: format-truncation.asm(13):
Fractional width 260 too long, limiting to 255
error: format-truncation.asm(13):
Formatted numeric value too long
warning: format-truncation.asm(13): [-Wlong-string]
String constant too long
error: format-truncation.asm(14):
Formatted string value too long
warning: format-truncation.asm(14): [-Wlong-string]
String constant too long
error: format-truncation.asm(15):
Formatted string value too long
warning: format-truncation.asm(15): [-Wlong-string]
String constant too long
error: Assembly aborted (12 errors)!
Fractional width 260 too long, limiting to 255
error: Assembly aborted (2 errors)!

View File

@@ -1,10 +1,10 @@
$00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
$000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a
$2a
000000000000000000000123.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000123.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
hello
<$0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
<$2a
<000000000000000000000123.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
<
<hello
hello
<$000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a>
<$2a >
<000000000000000000000123.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000>
< hello>
<hello >

View File

@@ -1,12 +1,10 @@
error: interpolation-overflow.asm(4):
Fractional width 99999999 too long, limiting to 255
error: interpolation-overflow.asm(4):
Formatted numeric value too long
warning: interpolation-overflow.asm(4): [-Wlarge-constant]
Precision of fixed-point constant is too large
while expanding symbol "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
while expanding symbol "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
error: interpolation-overflow.asm(4):
Macro argument '\1' not defined
error: interpolation-overflow.asm(4):
syntax error, unexpected number
error: Assembly aborted (4 errors)!
error: Assembly aborted (3 errors)!

View File

@@ -1,3 +1,3 @@
DEF n EQU 42
; the format spec is truncated to "000...009", omitting the "x", so this prints "000000042" not "00000002a"
; the format spec used to be truncated, but not any more
PRINTLN "{000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009x:n}"

View File

@@ -1,2 +1,2 @@
SECTION "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit", ROM0[0]
SECTION "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", ROM0[0]
println "This is section ", SECTION(@)

View File

@@ -1,2 +0,0 @@
warning: long-section-name.asm(1): [-Wlong-string]
String constant too long

View File

@@ -1 +1 @@
This is section Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor i
This is section Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

View File

@@ -1,13 +1,20 @@
println """This paragraph has exactly 257--that's two hundred and
fifty-seven--characters altogether. That's just enough for its last
two characters to be truncated by rgbasm's lexer, since it can't
handle more than 255-character strings. The final two won't print: !?"""
println """Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium dol-
oremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore verita-
tis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam vol-
uptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur
magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam
est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed
quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam
quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam
corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis
autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil mole-
stiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"""
MACRO mac
println "\1" ; x1
println "\1\1\1\1\1\1" ; x6
println "\1\1\1\1\1\1\1" ; x7
ENDM
mac Hello! ; 6x6 = 36
mac This sentence spans forty-three characters. ; 43x6 = 258
mac Hello! ; 6x7 = 42
mac This sentence spans forty-three characters. ; 43x7 = 301

View File

@@ -1,4 +0,0 @@
warning: long-string-constant.asm(5): [-Wlong-string]
String constant too long
warning: long-string-constant.asm(13) -> long-string-constant.asm::mac(9): [-Wlong-string]
String constant too long

View File

@@ -1,8 +1,15 @@
This paragraph has exactly 257--that's two hundred and
fifty-seven--characters altogether. That's just enough for its last
two characters to be truncated by rgbasm's lexer, since it can't
handle more than 255-character strings. The final two won't print:
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium dol-
oremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore verita-
tis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam vol-
uptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur
magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam
est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed
quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam
quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam
corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis
autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil mole-
stiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
Hello!
Hello!Hello!Hello!Hello!Hello!Hello!
Hello!Hello!Hello!Hello!Hello!Hello!Hello!
This sentence spans forty-three characters.
This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characte
This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.This sentence spans forty-three characters.

View File

@@ -15,7 +15,7 @@ ENDM
mac 1, 2 + /* another ;
; comment */ 2, 3
mac a b ; truncated
mac a b ; long
mac
mac ,

View File

@@ -1,5 +1,3 @@
warning: macro-arguments.asm(18): [-Wlong-string]
Macro argument too long
warning: macro-arguments.asm(21): [-Wempty-macro-arg]
Empty macro argument
warning: macro-arguments.asm(23): [-Wempty-macro-arg]

View File

@@ -13,8 +13,8 @@
\2: <2 + 2>
\3: <3>
'mac a':
\1: <a>
'mac a b':
\1: <a b>
'mac ':

View File

@@ -1,4 +1,2 @@
warning: strrpl.asm(4): [-Wempty-strrpl]
STRRPL: Cannot replace an empty string
warning: strrpl.asm(6): [-Wlong-string]
STRRPL: String too long, got truncated

View File

@@ -3,4 +3,4 @@ hahohahol
hello
world
[bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbb
[bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb][bbbbbbbb]