More GCC compatibility/warning fixes (#3118)

* Wrap >4-char literals in a MULTI_CHAR macro

Modern compilers do not support CW's non-standard behavior with
>4 char literals. We can, however, use a constexpr function to
compute the u64 values directly. This leaves <=4 char literals
unchanged.

* Replace non-pointer usages of NULL with 0

* Define NULL to nullptr on C++11 and above

* Fix more -Wpointer-arith and -Woverflow warnings

* Replace u32/s32 with uintptr_t/intptr_t where appropriate

* JSUOutputStream: Overload all standard int types
This commit is contained in:
Luke Street
2026-02-28 21:19:17 -07:00
committed by GitHub
parent b5d3b8c059
commit 6a48380461
169 changed files with 1849 additions and 1818 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ public:
J2DAnmVtxColor() {
mKind = KIND_VTX_COLOR;
for (int i = 0; i < ARRAY_SIZE(mAnmTableNum); i++) {
mAnmTableNum[i] = NULL;
mAnmTableNum[i] = 0;
}
for (int i = 0; i < ARRAY_SIZE(mVtxColorIndexData); i++) {
mVtxColorIndexData[i] = NULL;
+2 -2
View File
@@ -15,7 +15,7 @@ struct JASNonCopyable {
JASNonCopyable() {}
~JASNonCopyable() {}
/* 0x0 */ int field_0x0;
/* 0x0 */ void* field_0x0;
}; // Size: 0x4
/**
@@ -56,7 +56,7 @@ public:
mParams.init();
mMaxActiveSe = 0;
mMaxInactiveSe = 0;
field_0x0 = 0;
field_0x0 = NULL;
}
virtual bool isUsingSeqData(const JAISeqDataRegion& seqDataRegion);
+4 -3
View File
@@ -5,6 +5,7 @@
#include "JSystem/JAudio2/JAIAudible.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "global.h"
#include <cstdint>
class JAISound;
@@ -134,7 +135,7 @@ struct JAISoundStatus_ {
u8 flag8 : 1;
} flags;
} state;
/* 0x4 */ u32 userdata_;
/* 0x4 */ uintptr_t userdata_;
}; // Size: 0x8
/**
@@ -294,8 +295,8 @@ public:
void setAnimationState(u32 state) {
status_.state.flags.animationState = state;
}
u32 getUserData() const { return status_.userdata_; }
void setUserData(u32 userData) { status_.userdata_ = userData; }
uintptr_t getUserData() const { return status_.userdata_; }
void setUserData(uintptr_t userData) { status_.userdata_ = userData; }
JAIAudible* getAudible() { return audible_; }
bool isHandleAttached() const { return handle_ != NULL; }
bool hasLifeTime() const { return status_.field_0x1.flags.flag2; }
+1 -1
View File
@@ -112,7 +112,7 @@ namespace JASDsp {
void invalChannelAll();
void initBuffer();
int setFXLine(u8, s16*, JASDsp::FxlineConfig_*);
BOOL changeFXLineParam(u8, u8, u32);
BOOL changeFXLineParam(u8, u8, uintptr_t);
extern u8 const DSPADPCM_FILTER[64];
extern u32 const DSPRES_FILTER[320];
+3 -3
View File
@@ -8,10 +8,10 @@ namespace JASResArcLoader {
size_t getResSize(JKRArchive const*, u16);
size_t getResMaxSize(JKRArchive const*);
static void loadResourceCallback(void*);
int loadResourceAsync(JKRArchive*, u16, u8*, u32, void (*)(u32, u32), u32);
int loadResourceAsync(JKRArchive*, u16, u8*, u32, void (*)(u32, uintptr_t), uintptr_t);
// from pikmin2
typedef void (*LoadCallback)(u32, u32);
typedef void (*LoadCallback)(u32, uintptr_t);
struct TLoadResInfo {
inline TLoadResInfo(JKRArchive* archive, u16 id, void* buf, u32 size)
@@ -30,7 +30,7 @@ namespace JASResArcLoader {
void* mBuffer; // _08
u32 mBufferSize; // _0C
LoadCallback mCallback; // _10
u32 mCallbackArg; // _14, arg to pass to mCallback along with readResource result
uintptr_t mCallbackArg; // _14, arg to pass to mCallback along with readResource result
OSMessageQueue* mQueue; // _18
};
};
+2 -1
View File
@@ -5,6 +5,7 @@
#include <dolphin/os.h>
#include "global.h"
#include <new>
#include <cstdint>
class JKRHeap;
typedef void (*JKRErrorHandler)(void*, u32, int);
@@ -66,7 +67,7 @@ public:
JKRHeap* find(void* ptr) const;
JKRHeap* findAllHeap(void* ptr) const;
void dispose_subroutine(u32 start, u32 end);
void dispose_subroutine(uintptr_t start, uintptr_t end);
bool dispose(void* ptr, u32 size);
void dispose(void* begin, void* end);
void dispose();
+1 -1
View File
@@ -14,7 +14,7 @@ extern const char ga4cSignature[4];
const int PARAGRAPH_DATA = 1;
typedef enum TEComposite {
enum TEComposite {
/* 0x0 */ COMPOSITE_NONE,
/* 0x1 */ COMPOSITE_RAW,
/* 0x2 */ COMPOSITE_IDX,
+2 -1
View File
@@ -5,6 +5,7 @@
#include "JSystem/JStudio/JStudio/object-id.h"
#include "JSystem/JStudio/JStudio/stb-data-parse.h"
#include <dolphin/os.h>
#include <cstdint>
namespace JStudio {
class TObject;
@@ -86,7 +87,7 @@ public:
const void* getSequence() const { return pSequence; }
void setSequence_(const void* arg1) { pSequence = arg1; }
const void* getSequence_offset(s32 i_no) const {
int s32Val = (s32)getSequence();
intptr_t s32Val = (intptr_t)getSequence();
return (const void*)(s32Val + i_no);
}
const void* getSequence_next() const { return pSequence_next; }
+15 -21
View File
@@ -18,30 +18,24 @@ public:
s32 write(const void*, s32);
void write(const char*);
JSUOutputStream& operator<<(u32 param_0) {
write(&param_0, sizeof(u32));
return *this;
#define JSU_OUTPUTSTREAM_OPERATOR(T) \
JSUOutputStream& operator<<(T val) { \
write(&val, sizeof(T)); \
return *this; \
}
JSUOutputStream& operator<<(s32 param_0) {
write(&param_0, sizeof(s32));
return *this;
}
JSU_OUTPUTSTREAM_OPERATOR(signed char)
JSU_OUTPUTSTREAM_OPERATOR(unsigned char)
JSU_OUTPUTSTREAM_OPERATOR(signed short)
JSU_OUTPUTSTREAM_OPERATOR(unsigned short)
JSU_OUTPUTSTREAM_OPERATOR(int)
JSU_OUTPUTSTREAM_OPERATOR(unsigned int)
JSU_OUTPUTSTREAM_OPERATOR(signed long)
JSU_OUTPUTSTREAM_OPERATOR(unsigned long)
JSU_OUTPUTSTREAM_OPERATOR(signed long long)
JSU_OUTPUTSTREAM_OPERATOR(unsigned long long)
JSUOutputStream& operator<<(s16 param_0) {
write(&param_0, sizeof(s16));
return *this;
}
JSUOutputStream& operator<<(u16 param_0) {
write(&param_0, sizeof(u16));
return *this;
}
JSUOutputStream& operator<<(u8 param_0) {
write(&param_0, sizeof(u8));
return *this;
}
#undef JSU_OUTPUTSTREAM_OPERATOR
JSUOutputStream& operator<<(const char* param_0) {
write(param_0);
+1 -1
View File
@@ -20,7 +20,7 @@ T* JSUConvertOffsetToPtr(const void* ptr, uintptr_t offset) {
template <typename T>
T* JSUConvertOffsetToPtr(const void* ptr, const void* offset) {
T* ret;
if (offset == NULL) {
if (offset == 0) {
ret = NULL;
} else {
ret = (T*)((intptr_t)ptr + (intptr_t)offset);
+1 -1
View File
@@ -75,7 +75,7 @@ private:
static JUTXfb* sManager;
private:
/* 0x00 */ void* mBuffer[3];
/* 0x00 */ u8* mBuffer[3];
/* 0x0C */ bool mXfbAllocated[3];
/* 0x10 */ s32 mBufferNum;
/* 0x14 */ s16 mDrawingXfbIndex;
+25 -25
View File
@@ -573,7 +573,7 @@ public:
virtual roomRead_class* getRoom(void) const {
OSReport("Room non room data !!\n");
JUT_ASSERT(2100, FALSE);
return NULL;
return 0;
}
virtual void setMapInfo(stage_map_info_class* i_MapInfo) { mMapInfo = i_MapInfo; }
virtual stage_map_info_class* getMapInfo(void) const { return mMapInfo; }
@@ -589,7 +589,7 @@ public:
virtual stage_palette_info_class* getPaletteInfo(void) const {
OSReport("Room non palet data !!\n");
JUT_ASSERT(2130, FALSE);
return NULL;
return 0;
}
virtual void setPselectInfo(stage_pselect_info_class* i_PselectInfo) {
UNUSED(i_PselectInfo);
@@ -600,7 +600,7 @@ public:
virtual stage_pselect_info_class* getPselectInfo(void) const {
OSReport("Room non pselect data !!\n");
JUT_ASSERT(2141, FALSE);
return NULL;
return 0;
}
virtual void setEnvrInfo(stage_envr_info_class* i_EnvrInfo) {
UNUSED(i_EnvrInfo);
@@ -611,7 +611,7 @@ public:
virtual stage_envr_info_class* getEnvrInfo(void) const {
OSReport("Room non envr data !!\n");
JUT_ASSERT(2152, FALSE);
return NULL;
return 0;
}
virtual void setVrboxInfo(stage_vrbox_info_class* i_VrboxInfo) { mVrboxInfo = i_VrboxInfo; }
virtual stage_vrbox_info_class* getVrboxInfo(void) const { return mVrboxInfo; }
@@ -626,7 +626,7 @@ public:
virtual stage_plight_info_class* getPlightInfo(void) const {
OSReport("Room non plight data !!\n");
JUT_ASSERT(2178, FALSE);
return NULL;
return 0;
}
virtual void setPaletteNumInfo(int i_PaletteNumInfo) {
UNUSED(i_PaletteNumInfo);
@@ -637,7 +637,7 @@ public:
virtual int getPaletteNumInfo(void) const {
OSReport("Room non palette num data !!\n");
JUT_ASSERT(2190, FALSE);
return NULL;
return 0;
}
virtual void setPselectNumInfo(int i_PselectNumInfo) {
UNUSED(i_PselectNumInfo);
@@ -648,7 +648,7 @@ public:
virtual int getPselectNumInfo(void) const {
OSReport("Room non pselect num data !!\n");
JUT_ASSERT(2201, FALSE);
return NULL;
return 0;
}
virtual void setEnvrNumInfo(int i_EnvrNumInfo) {
UNUSED(i_EnvrNumInfo);
@@ -659,7 +659,7 @@ public:
virtual int getEnvrNumInfo(void) const {
OSReport("Room non envr num data !!\n");
JUT_ASSERT(2212, FALSE);
return NULL;
return 0;
}
virtual void setVrboxNumInfo(int i_VrboxNumInfo) { mVrboxNumInfo = i_VrboxNumInfo; }
virtual int getVrboxNumInfo(void) const { return mVrboxNumInfo; }
@@ -674,7 +674,7 @@ public:
virtual int getPlightNumInfo(void) const {
OSReport("Room non plight num data !!\n");
JUT_ASSERT(2227, FALSE);
return NULL;
return 0;
}
virtual void setLightVecInfo(stage_pure_lightvec_info_class* i_LightVecInfo) { mLightVecInfo = i_LightVecInfo; }
virtual stage_pure_lightvec_info_class* getLightVecInfo(void) const { return mLightVecInfo; }
@@ -689,7 +689,7 @@ public:
virtual stage_stag_info_class* getStagInfo(void) const {
OSReport("Room non stag data !!\n");
JUT_ASSERT(2260, FALSE);
return NULL;
return 0;
}
virtual void setSclsInfo(stage_scls_info_dummy_class* i_SclsInfo) { mSclsInfo = i_SclsInfo; }
virtual stage_scls_info_dummy_class* getSclsInfo(void) const { return mSclsInfo; }
@@ -702,7 +702,7 @@ public:
virtual dStage_dPnt_c* getPntInf(void) const {
OSReport("Room non Pnts data !\n");
JUT_ASSERT(2285, FALSE);
return NULL;
return 0;
}
virtual void setPathInfo(dStage_dPath_c* i_PathInfo) {
UNUSED(i_PathInfo);
@@ -713,7 +713,7 @@ public:
virtual dStage_dPath_c* getPathInf(void) const {
OSReport("Room non Path data !\n");
JUT_ASSERT(2296, FALSE);
return NULL;
return 0;
}
virtual void setPnt2Info(dStage_dPnt_c* i_Pnt2Info) { mPnt2Info = i_Pnt2Info; }
virtual dStage_dPnt_c* getPnt2Inf(void) const { return mPnt2Info; }
@@ -739,7 +739,7 @@ public:
virtual dStage_MemoryConfig_c* getMemoryConfig(void) const {
OSReport("Room non memory config data!\n");
JUT_ASSERT(2423, FALSE);
return NULL;
return 0;
}
virtual void setMemoryMap(dStage_MemoryMap_c* i_MemoryMap) {
UNUSED(i_MemoryMap);
@@ -749,7 +749,7 @@ public:
virtual dStage_MemoryMap_c* getMemoryMap(void) const {
OSReport("Room non memory map data!\n");
JUT_ASSERT(2442, FALSE);
return NULL;
return 0;
}
virtual void setMulti(dStage_Multi_c* i_Multi) {
UNUSED(i_Multi);
@@ -759,7 +759,7 @@ public:
virtual dStage_Multi_c* getMulti(void) const {
OSReport("Room non multi data!\n");
JUT_ASSERT(2457, FALSE);
return NULL;
return 0;
}
virtual void setOldMulti(void) {
OSReport("Room non old multi data!\n");
@@ -772,7 +772,7 @@ public:
virtual dStage_Multi_c* getOldMulti(void) const {
OSReport("Room non old multi data!\n");
JUT_ASSERT(2472, FALSE);
return NULL;
return 0;
}
virtual void setLbnk(dStage_Lbnk_c* i_Lbnk) { mLbnk = i_Lbnk; }
virtual dStage_Lbnk_c* getLbnk(void) const { return mLbnk; }
@@ -786,7 +786,7 @@ public:
virtual dStage_DMap_c* getDMap(void) const {
OS_REPORT("Room non DMap data\n");
JUT_ASSERT(2513, FALSE);
return NULL;
return 0;
}
virtual void setDrTg(stage_tgsc_class* i_DrTg) { mDrTg = i_DrTg; }
virtual stage_tgsc_class* getDrTg(void) const { return mDrTg; }
@@ -804,7 +804,7 @@ public:
virtual void* getMapPath(void) {
OSReport("stage non 2d map path data !!\n");
JUT_ASSERT(2561, FALSE);
return NULL;
return 0;
}
virtual void setElst(dStage_Elst_c* i_Elst) {
UNUSED(i_Elst);
@@ -815,7 +815,7 @@ public:
virtual dStage_Elst_c* getElst(void) {
dStage_SetErrorRoom();
OSReport("Room no Elst Data!!\n");
return NULL;
return 0;
}
public:
@@ -901,7 +901,7 @@ public:
/* vt[43] */ virtual stage_pure_lightvec_info_class* getLightVecInfo(void) const {
OSReport("stage non LightVec data !!\n");
JUT_ASSERT(3007, FALSE);
return NULL;
return 0;
}
/* vt[44] */ virtual void setLightVecInfoNum(int i_LightVecInfoNum) {
UNUSED(i_LightVecInfoNum);
@@ -912,7 +912,7 @@ public:
/* vt[45] */ virtual int getLightVecInfoNum(void) const {
OSReport("stage non LightVecNum data !!\n");
JUT_ASSERT(3018, FALSE);
return NULL;
return 0;
}
/* vt[40] */ virtual void setPlightNumInfo(int i_PlightNumInfo) { mPlightNumInfo = i_PlightNumInfo; }
/* vt[41] */ virtual int getPlightNumInfo(void) const { return mPlightNumInfo; }
@@ -943,7 +943,7 @@ public:
/* vt[65] */ virtual dStage_FileList2_dt_c* getFileList2Info(void) const {
OSReport("stage non filelist2 data!\n");
JUT_ASSERT(3127, FALSE);
return NULL;
return 0;
}
/* vt[66] */ virtual void setFileListInfo(dStage_FileList_dt_c* list) {
UNUSED(list);
@@ -954,7 +954,7 @@ public:
/* vt[67] */ virtual dStage_FileList_dt_c* getFileListInfo(void) const {
OSReport("stage non filelist data!\n");
JUT_ASSERT(3142, FALSE);
return NULL;
return 0;
}
/* vt[68] */ virtual void setFloorInfo(dStage_FloorInfo_c* i_FloorInfo) { mFloorInfo = i_FloorInfo; }
/* vt[69] */ virtual dStage_FloorInfo_c* getFloorInfo(void) const { return mFloorInfo; }
@@ -976,7 +976,7 @@ public:
/* vt[80] */ virtual dStage_Lbnk_c* getLbnk(void) const {
OSReport("stage non Lbnk data!\n");
JUT_ASSERT(3238, FALSE);
return NULL;
return 0;
}
/* vt[81] */ virtual void setTresure(stage_tresure_class* i_Tresure) { mTresure = i_Tresure; }
/* vt[82] */ virtual stage_tresure_class* getTresure(void) const { return mTresure; }
@@ -995,7 +995,7 @@ public:
virtual void* getUnit() {
OSReport("stage non unit list data !!\n");
JUT_ASSERT(3325, 0);
return NULL;
return 0;
}
#endif
/* vt[89] */ virtual void setMapPath(void* i_MapPath) { return; }
+5 -1
View File
@@ -69,8 +69,12 @@ typedef unsigned int uint;
#endif
#ifndef NULL
#ifdef __cplusplus
#ifdef __cplusplus
#if __cplusplus >= 201103L
#define NULL nullptr
#else
#define NULL 0
#endif
#else
#define NULL ((void*)0)
#endif
+1 -1
View File
@@ -199,7 +199,7 @@ public:
BOOL chkCondition(u16 condition) { return (mCondition & condition) == condition; }
void suspendProc(void* actor) {
if (field_0x10 != NULL) {
if (field_0x10 != 0) {
field_0x14(actor);
}
}
+8 -1
View File
@@ -423,7 +423,14 @@ inline BOOL fopAcM_CULLSIZE_IS_BOX(int i_culltype) {
i_culltype == fopAc_CULLBOX_CUSTOM_e;
}
inline const cXyz& fopAcM_getCullSizeSphereCenter(const fopAc_ac_c* i_actor) {
inline
#ifdef __MWERKS__
// In the original code, this constructs a temporary and returns a reference to it
const cXyz&
#else
const Vec&
#endif
fopAcM_getCullSizeSphereCenter(const fopAc_ac_c* i_actor) {
return i_actor->cull.sphere.center;
}
+3 -2
View File
@@ -4,14 +4,15 @@
#include "f_op/f_op_scene_pause.h"
#include "f_pc/f_pc_manager.h"
#include "f_op/f_op_scene.h"
#include <cstdint>
typedef struct base_process_class base_process_class;
scene_class* fopScnM_SearchByID(fpc_ProcID id);
int fopScnM_ChangeReq(scene_class* i_scene, s16 i_procName, s16 param_3, u16 param_4);
fpc_ProcID fopScnM_DeleteReq(scene_class* i_scene);
int fopScnM_CreateReq(s16 i_procName, s16 param_2, u16 param_3, u32 i_data);
u32 fopScnM_ReRequest(s16 i_procName, u32 i_data);
int fopScnM_CreateReq(s16 i_procName, s16 param_2, u16 param_3, uintptr_t i_data);
u32 fopScnM_ReRequest(s16 i_procName, uintptr_t i_data);
void fopScnM_Management();
void fopScnM_Init();
+19
View File
@@ -145,6 +145,25 @@ static const float INF = 2000000000.0f;
#define UNSET_FLAG(var, flag, type) (var) &= ~(flag)
#endif
// Macro for multi-character literals that exceed 4 bytes (e.g. 'ari_os').
// CW encodes all characters in big-endian order into the full integer, but GCC/Clang
// truncate multi-char constants to int (4 bytes). This macro produces matching u64
// values on all compilers. For <=4-char literals, raw constants like 'ABCD' are fine.
#ifdef __MWERKS__
#define MULTI_CHAR(x) (x)
#else
template <int N>
inline constexpr unsigned long long MultiCharLiteral(const char (&buf)[N]) {
static_assert(N - 1 >= 3 && N - 1 <= 10, "MULTI_CHAR literal must be 1-8 characters");
unsigned long long out = 0;
for (int i = 1; i < N - 2; i++) {
out = (out << 8) | static_cast<unsigned char>(buf[i]);
}
return out;
}
#define MULTI_CHAR(x) MultiCharLiteral(#x)
#endif
// potential fakematch?
#if DEBUG
#define FABSF fabsf
+5 -1
View File
@@ -66,8 +66,12 @@ typedef unsigned int uint;
#endif
#ifndef NULL
#ifdef __cplusplus
#ifdef __cplusplus
#if __cplusplus >= 201103L
#define NULL nullptr
#else
#define NULL 0
#endif
#else
#define NULL ((void*)0)
#endif