mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use QUOTEDSTRLEN macro instead of sizeof or strlen
This commit is contained in:
@@ -86,6 +86,9 @@ static inline int clz(unsigned int x) {
|
||||
// For lack of <ranges>, this adds some more brevity
|
||||
#define RANGE(s) std::begin(s), std::end(s)
|
||||
|
||||
// MSVC does not inline `strlen()` or `.length()` of a constant string, so we use `sizeof`
|
||||
#define QUOTEDSTRLEN(s) (sizeof(s) - 1)
|
||||
|
||||
// For ad-hoc RAII in place of a `defer` statement or cross-platform `__attribute__((cleanup))`
|
||||
template<typename T>
|
||||
struct Defer {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "helpers.hpp" // QUOTEDSTRLEN
|
||||
#include "util.hpp"
|
||||
|
||||
#include "asm/fixpoint.hpp"
|
||||
@@ -2233,7 +2234,7 @@ Capture lexer_CaptureRept() {
|
||||
endCapture(capture);
|
||||
// The final ENDR has been captured, but we don't want it!
|
||||
// We know we have read exactly "ENDR", not e.g. an EQUS
|
||||
capture.span.size -= strlen("ENDR");
|
||||
capture.span.size -= QUOTEDSTRLEN("ENDR");
|
||||
return capture;
|
||||
}
|
||||
depth--;
|
||||
@@ -2279,7 +2280,7 @@ Capture lexer_CaptureMacro() {
|
||||
endCapture(capture);
|
||||
// The ENDM has been captured, but we don't want it!
|
||||
// We know we have read exactly "ENDM", not e.g. an EQUS
|
||||
capture.span.size -= strlen("ENDM");
|
||||
capture.span.size -= QUOTEDSTRLEN("ENDM");
|
||||
return capture;
|
||||
|
||||
default:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "error.hpp"
|
||||
#include "extern/getopt.hpp"
|
||||
#include "helpers.hpp" // Defer
|
||||
#include "helpers.hpp"
|
||||
#include "parser.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
@@ -45,7 +45,7 @@ static std::string make_escape(std::string &str) {
|
||||
break;
|
||||
escaped.append(str, pos, nextPos - pos);
|
||||
escaped.append("$$");
|
||||
pos = nextPos + sizeof("$") - 1;
|
||||
pos = nextPos + QUOTEDSTRLEN("$");
|
||||
}
|
||||
escaped.append(str, pos, str.length() - pos);
|
||||
return escaped;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "helpers.hpp" // QUOTEDSTRLEN
|
||||
#include "itertools.hpp"
|
||||
|
||||
#include "asm/fstack.hpp"
|
||||
@@ -230,8 +231,8 @@ void processWarningFlag(char const *flag) {
|
||||
}
|
||||
|
||||
// If it's not a meta warning, specially check against `-Werror`
|
||||
if (!strncmp(flag, "error", strlen("error"))) {
|
||||
char const *errorFlag = flag + strlen("error");
|
||||
if (!strncmp(flag, "error", QUOTEDSTRLEN("error"))) {
|
||||
char const *errorFlag = flag + QUOTEDSTRLEN("error");
|
||||
|
||||
switch (*errorFlag) {
|
||||
case '\0':
|
||||
@@ -254,9 +255,9 @@ void processWarningFlag(char const *flag) {
|
||||
|
||||
WarningState state = setError ? WARNING_ERROR
|
||||
// Not an error, then check if this is a negation
|
||||
: strncmp(flag, "no-", strlen("no-")) ? WARNING_ENABLED
|
||||
: WARNING_DISABLED;
|
||||
char const *rootFlag = state == WARNING_DISABLED ? flag + strlen("no-") : flag;
|
||||
: strncmp(flag, "no-", QUOTEDSTRLEN("no-")) ? WARNING_ENABLED
|
||||
: WARNING_DISABLED;
|
||||
char const *rootFlag = state == WARNING_DISABLED ? flag + QUOTEDSTRLEN("no-") : flag;
|
||||
|
||||
// Is this a "parametric" warning?
|
||||
if (state != WARNING_DISABLED) { // The `no-` form cannot be parametrized
|
||||
|
||||
@@ -632,9 +632,9 @@ static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>>
|
||||
char *ptr = buf;
|
||||
for (uint16_t cgbColor : list) {
|
||||
sprintf(ptr, ", $%04x", cgbColor);
|
||||
ptr += 7;
|
||||
ptr += QUOTEDSTRLEN(", $XXXX");
|
||||
}
|
||||
return &buf[2];
|
||||
return &buf[QUOTEDSTRLEN(", ")];
|
||||
};
|
||||
|
||||
// Iterate through proto-palettes, and try mapping them to the specified palettes
|
||||
|
||||
Reference in New Issue
Block a user