Max Freedom Pollard
631ef003e7
Avoid signed overflow in RGBLINK's +, -, and * ( #2060 )
...
RGBASM computes these with unsigned arithmetic and casts back, since
signed overflow is UB in C++, but RGBLINK's RPN evaluator used `int32_t`
directly, so `src/link/patch.cpp` tripped UBSan on lines 117, 121, and
124. Share the three operators through `opmath.cpp` so both evaluators
stay in step.
2026-09-07 16:15:07 -04:00
Rangi
fdd6cece30
Warn about signed 8-bit truncation for add sp, e8 and ld hl, sp + e8
2026-09-07 19:28:45 +02:00
Rangi
b36028d1d1
Avoid unsigned overflow in INCBIN slice size check
2026-08-25 15:47:27 -04:00
Rangi
a2c52caca2
Disallow NUL characters in section names and assertion messages
...
Allowing these in object files would lose anything after the '\0'
when RGBLINK reads the object.
2026-08-22 19:51:03 -04:00
Rangi
21a4b85a4f
Fix STRFMT stopping at NUL characters in format spec strings
2026-08-22 19:23:49 -04:00
Rangi
9fa5058add
Correct error message for macro arg \<-INT_MIN>
2026-08-22 19:02:23 -04:00
Rangi
e287ee2724
Fix C++ UB from negating INT_MIN with macro shift INT_MIN
2026-08-22 18:48:36 -04:00
Rangi
80c8e77b19
Fixed-point FMOD and LOG explicitly return 0 for some invalid inputs
...
This is consistent with `fix_Div`'s explicit error handling,
and does not rely on subtle C/C++ `fmod` or `log` IEEE 754 behavior.
2026-07-23 00:38:44 -04:00
Rangi
50678d0942
Use _fseeki64/_ftelli64 on Windows since fseek/fell are limited by 32-bit long
2026-07-21 14:38:14 -04:00
Rangi
c691ec6607
Use std::optional<uint64_t> instead of long with a special -1 sentinel for seekSize
2026-07-21 14:31:05 -04:00
Rangi
7e2a3491a5
Encapsulate fseek+ftell idiom in seekSize
...
This allows a single check for the return value of `seekSize`
to verify all three `fseek`+`ftell`+`fseek` calls.
2026-07-14 01:32:18 -04:00
Rangi
304cbb464f
Factor out verboseDo to encapsulate magenta output color
2026-07-13 18:05:55 -04:00
Rangi
e9fa1e4e94
Avoid closing stdin/stdout/stderr standard streams
2026-07-13 13:02:46 -04:00
Rangi
b8011947a8
Correct assumption to avoid UB with 1 << 31
2026-07-09 21:36:34 -04:00
Rangi
b219e03b38
Use more structured bindings
2026-07-08 16:38:32 -04:00
Rangi
824ebd80f9
Use [[fallthrough]]; attribute instead of // fallthrough comment
2026-07-08 16:30:52 -04:00
Rangi
ed8e3e4d02
Reset errno = 0 before parseWholeNumber calls and errno == ERANGE checks
2026-07-07 17:02:46 -04:00
Rangi
21682e8814
Consistently handle negative shifted macro args ( #2014 )
...
Negative macro arguments count from the end, i.e. `\<-1>`
is equivalent to `\<_NARG>`, even after `shift`ing them.
Negative arguments cannot be used to access shifted values.
2026-07-07 02:19:37 -04:00
Rangi
f82b0838a1
Disallow minus sign before symbol name in bracketed macro arguments ( #2015 )
...
This was being silently allowed but without actually negating the symbol's value
2026-07-07 00:42:09 -04:00
Rangi
dabd0a08d2
Remove impossible condition (uint64_t > UINT64_MAX)
2026-07-06 23:08:05 -04:00
Rangi
c3e10dbb03
Safeguard against localtime or gmtime failure
2026-07-06 23:05:19 -04:00
Rangi
1e4a060d9e
Guard against undefined behavior in double2fix
...
I haven't found input which triggers any, but this is more
technically correct just in case.
2026-07-06 22:38:06 -04:00
Rangi
fe3b238dea
Do not allow defining labels outside sections ( #2013 )
...
Creating a `Symbol` with `type = SYM_LABEL` but `section = nullptr`
is inconsistent and dangerous. I was not able to cause any buggy
behavior so far, but it's safer and reasonable to not create such
a symbol in the first place.
The main consequence is that `DEF(LabelOutsideSection)` will now
evaluate as 0.
2026-07-06 16:18:42 -04:00
Rangi
46a6966b70
Fix $8000_0000 % -1 to warn with -Wdiv like $8000_0000 / -1 does ( #2012 )
2026-07-06 15:08:44 -04:00
Rangi
6e643406a2
Refactor warning diagnostic code to reduce repeated output logic
2026-07-04 23:02:16 -04:00
Rangi
799c55b4dd
Add [[gnu::format(printf, 1, 2)]] attribute to variadic function sectError
2026-07-04 23:02:16 -04:00
Rangi
ddd8f37508
Remove unnecessary default constructor for Token
2026-07-04 18:48:03 -04:00
Rangi
0996a2f5ed
Encapuslate UTF-8 decoder state in a struct
2026-07-03 19:35:23 -04:00
Rangi
daba94b495
Remove pointless std::move from non-move constructor
2026-07-03 13:12:29 -04:00
Rangi
9bbb2247a7
Fix rgbasm -Werror=... not adding to the final error count
2026-07-03 13:05:33 -04:00
Rangi
0b91bf654b
Rename BaseV to ValidBaseV
2026-06-09 17:55:38 -04:00
Rangi
075f132d77
Use a smaller unordered_map just for looking up line-leading keywords
2026-05-27 22:01:20 -04:00
Rangi
31e1d2ec87
Do not build up a std::string when skipping leading keywords
2026-05-27 22:01:20 -04:00
Rangi
007672f080
Intern identifier strings only after checking for keywords
2026-05-25 23:55:57 -04:00
Rangi
55db252a8f
Simplify the lexer by removing BufferedContent and inlining ViewedContent ( #1981 )
...
Instead of reading 64 characters at a time into a rolling buffer
as `shiftChar()` is called, we read 8192 characters at a time into
a complete buffer before any `peek()`/`shiftChar()` operations.
2026-05-25 21:05:59 -04:00
Rangi
cfa0adf295
Intern strings used as identifiers (for labels, constants, macros, charmaps, etc) ( #1980 )
2026-05-25 16:22:29 -04:00
Rangi
ed19806434
Don't hard-code std::string as the key type for InsertionOrderedMap
2026-05-25 14:21:18 -04:00
Rangi
a0d96a0856
Factor out repeated expandedSymName logic
2026-05-25 14:21:18 -04:00
Rangi
4b992bfea5
Use the name of sym_GetPC() instead of hard-coding "@" again
2026-05-25 14:21:14 -04:00
Rangi
141a7fe22b
Add assume checks for expected Token types, like RPNValue has for RPNCommands
2026-05-25 14:14:34 -04:00
Rangi
72a410c007
Encapsulate charmap_Init, like sym_Init
2026-05-25 13:54:26 -04:00
Rangi
090768e2c9
Some Expansion references can be const
2026-05-23 13:06:09 -04:00
Rangi
4a173130b9
Optimize skipToLeadingKeyword for the common ViewedContent case ( #1968 )
2026-05-22 19:06:12 -04:00
Rangi
ef2f021892
Simplify sectError handling, without the need for an empty-string sentinel
...
The `errorNoTrace` case for the empty-string sentinel was unreachable,
so we can just have a `fatalNoTrace` error right away.
2026-05-22 18:17:25 -04:00
Rangi
dce14fd4b8
Use C++20 concepts to require constraints on template parameters ( #1977 )
2026-05-22 17:54:34 -04:00
Rangi
728bed39d5
Do not support GCC 9 ( #1978 )
...
This will let us use C++20 features that GCC 9's experimental
C++20 support did not yet cover, such as "concepts".
This reverts some commits:
- 6bcd79b997
- d5ce5329ea
- 728d14879b
2026-05-22 16:46:46 -04:00
Rangi
48fcd9a0ca
Use templates to reduce the redundant number-lexing functions ( #1963 )
2026-05-21 23:13:09 +02:00
Rangi
d56dbbb4bf
Refactor section creation errors, and simplify output for single errors ( #1964 )
2026-05-21 13:01:08 -04:00
Rangi
c50a849757
Verbose tracing shows lexed and captured values ( #1969 )
2026-05-09 12:01:29 -04:00
Rangi42
f0161b41c8
Update readHexNumber for consistency with other routines
2026-04-29 12:31:00 +02:00