mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
-Wmacro-shift warns about shifting macro arguments too far (#741)
Fixes #735
This commit is contained in:
@@ -168,12 +168,17 @@ void macro_ShiftCurrentArgs(int32_t count)
|
||||
{
|
||||
if (!macroArgs) {
|
||||
error("Cannot shift macro arguments outside of a macro\n");
|
||||
} else if (macroArgs->shift < macroArgs->nbArgs) {
|
||||
} else if (count > 0 && (count > macroArgs->nbArgs
|
||||
|| macroArgs->shift > macroArgs->nbArgs - count)) {
|
||||
warning(WARNING_MACRO_SHIFT,
|
||||
"Cannot shift macro arguments past their end\n");
|
||||
macroArgs->shift = macroArgs->nbArgs;
|
||||
} else if (count < 0 && macroArgs->shift < -count) {
|
||||
warning(WARNING_MACRO_SHIFT,
|
||||
"Cannot shift macro arguments past their beginning\n");
|
||||
macroArgs->shift = 0;
|
||||
} else {
|
||||
macroArgs->shift += count;
|
||||
if (macroArgs->shift > macroArgs->nbArgs)
|
||||
macroArgs->shift = macroArgs->nbArgs;
|
||||
else if (macroArgs->shift < 0)
|
||||
macroArgs->shift = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,6 +229,10 @@ This warning is enabled by
|
||||
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
|
||||
.Fl Wextra .
|
||||
.It Fl Wno-obsolete
|
||||
Warn when obsolete constructs such as the
|
||||
.Ic _PI
|
||||
|
||||
@@ -38,6 +38,7 @@ static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
||||
[WARNING_EMPTY_STRRPL] = WARNING_DISABLED,
|
||||
[WARNING_LARGE_CONSTANT] = WARNING_DISABLED,
|
||||
[WARNING_LONG_STR] = WARNING_DISABLED,
|
||||
[WARNING_MACRO_SHIFT] = WARNING_DISABLED,
|
||||
[WARNING_NESTED_COMMENT] = WARNING_ENABLED,
|
||||
[WARNING_OBSOLETE] = WARNING_ENABLED,
|
||||
[WARNING_SHIFT] = WARNING_DISABLED,
|
||||
@@ -79,6 +80,7 @@ static char const *warningFlags[NB_WARNINGS_ALL] = {
|
||||
"empty-strrpl",
|
||||
"large-constant",
|
||||
"long-string",
|
||||
"macro-shift",
|
||||
"nested-comment",
|
||||
"obsolete",
|
||||
"shift",
|
||||
@@ -110,6 +112,7 @@ static uint8_t const _wallCommands[] = {
|
||||
/* Warnings that are less likely to indicate an error */
|
||||
static uint8_t const _wextraCommands[] = {
|
||||
WARNING_EMPTY_ENTRY,
|
||||
WARNING_MACRO_SHIFT,
|
||||
WARNING_NESTED_COMMENT,
|
||||
META_WARNING_DONE
|
||||
};
|
||||
@@ -123,6 +126,7 @@ static uint8_t const _weverythingCommands[] = {
|
||||
WARNING_EMPTY_STRRPL,
|
||||
WARNING_LARGE_CONSTANT,
|
||||
WARNING_LONG_STR,
|
||||
WARNING_MACRO_SHIFT,
|
||||
WARNING_NESTED_COMMENT,
|
||||
WARNING_OBSOLETE,
|
||||
WARNING_SHIFT,
|
||||
|
||||
Reference in New Issue
Block a user