Fix bugs/warnings from static analysis

This commit is contained in:
MysterD 2022-02-20 20:02:48 -08:00
parent 13ecef0b0a
commit 69fb69dfce
42 changed files with 144 additions and 101 deletions

View file

@ -95,8 +95,8 @@ ifeq ($(WINDOWS_AUTO_BUILDER),1)
EXTRA_INCLUDES := -I ../include/1 -I ../include/2 -I ../include/3 -I ../include/4
EXTRA_CFLAGS := -Wno-expansion-to-defined
else
EXTRA_INCLUDES :=
EXTRA_CFLAGS :=
EXTRA_INCLUDES ?=
EXTRA_CFLAGS ?=
endif
EXTRACT_ASSETS := $(PYTHON) ./extract_assets.py
@ -591,7 +591,7 @@ SDL1_USED := 0
SDL2_USED := 0
# suppress warnings
BACKEND_CFLAGS += -Wno-format-truncation
BACKEND_CFLAGS += -Wno-format-truncation -Wno-format-security -Wno-trigraphs
BACKEND_CFLAGS += $(EXTRA_CFLAGS)
# for now, it's either SDL+GL or DXGI+DirectX, so choose based on WAPI
@ -652,19 +652,19 @@ ifneq ($(SDL1_USED)$(SDL2_USED),00)
endif
ifeq ($(WINDOWS_BUILD),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -DWINSOCK
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -DWINSOCK
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -DWINSOCK
ifeq ($(TARGET_BITS), 32)
BACKEND_LDFLAGS += -ldbghelp
endif
else ifeq ($(TARGET_WEB),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
# Linux / Other builds below
else
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
endif

View file

@ -0,0 +1,2 @@
#!/bin/bash
make clean ; scan-build -disable-checker deadcode.DeadStores make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 DEVELOPMENT=1 STRICT=1 EXTRA_INCLUDES="-IC:/msys64/mingw64/include" -j

View file

@ -222,6 +222,10 @@ void *soundAlloc(struct SoundAllocPool *pool, u32 size) {
#else
u32 alignedSize = ALIGN16(size);
if (pool == NULL || pool->cur == NULL) {
return NULL;
}
u8* start = pool->cur;
if ((start + alignedSize <= pool->size + pool->start)) {
bzero(start, alignedSize);
@ -328,7 +332,7 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
u16 secondVal;
#endif
u32 nullID = -1;
u8 *table;
u8 *table = NULL;
u8 isSound;
#ifndef VERSION_EU
u16 firstVal;
@ -349,6 +353,10 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
isSound = TRUE;
}
if (table == NULL) {
return NULL;
}
firstVal = (tp->entries[0].id == (s8)nullID ? SOUND_LOAD_STATUS_NOT_LOADED : table[tp->entries[0].id]);
secondVal = (tp->entries[1].id == (s8)nullID ? SOUND_LOAD_STATUS_NOT_LOADED : table[tp->entries[1].id]);

View file

@ -758,8 +758,8 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
}
struct AudioBank *load_banks_immediate(s32 seqId, u8 *arg1) {
void *ret;
u32 bankId;
void *ret = NULL;
u32 bankId = 0;
u16 offset;
u8 i;

View file

@ -1020,7 +1020,7 @@ GLOBAL_ASM("asm/non_matchings/seq_channel_layer_process_script_us.s")
#endif
u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr) {
struct Instrument *inst;
struct Instrument *inst = NULL;
#ifdef VERSION_EU
inst = get_instrument_inner(seqChannel->bankId, instId);
if (inst == NULL)
@ -1063,8 +1063,10 @@ u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrume
|| ((uintptr_t) gBankLoadedPool.temporary.pool.start <= (uintptr_t) inst
&& (uintptr_t) inst <= (uintptr_t)(gBankLoadedPool.temporary.pool.start
+ gBankLoadedPool.temporary.pool.size))) {
if (inst != NULL) {
adsr->envelope = inst->envelope;
adsr->releaseRate = inst->releaseRate;
}
*instOut = inst;
instId++;
return instId;
@ -1114,7 +1116,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
u8 cmd; // v1, s1
u8 loBits; // t0, a0
s32 offset;
s8 value; // sp53, 4b
s8 value = 0; // sp53, 4b
u8 temp;
s8 tempSigned;
UNUSED u8 temp2;
@ -1678,7 +1680,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
u8 cmd;
u8 loBits;
u8 temp;
s32 value;
s32 value = 0;
s32 i;
u16 u16v;
u32 u32v;

View file

@ -600,11 +600,11 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
UNUSED u8 pad7[0x0c]; // sp100
UNUSED s32 tempBufLen;
#ifdef VERSION_EU
s32 sp130; //sp128, sp104
s32 sp130 = 0; //sp128, sp104
UNUSED u32 pad9;
#else
UNUSED u32 pad9;
s32 sp130; //sp128, sp104
s32 sp130 = 0; //sp128, sp104
#endif
s32 nAdpcmSamplesProcessed; // signed required for US
s32 t0;

View file

@ -17,7 +17,7 @@ void *vec3f_copy(Vec3f dest, Vec3f src) {
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Set vector 'dest' to (x, y, z)
@ -25,7 +25,7 @@ void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) {
dest[0] = x;
dest[1] = y;
dest[2] = z;
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Add vector 'a' to 'dest'
@ -33,7 +33,7 @@ void *vec3f_add(Vec3f dest, Vec3f a) {
dest[0] += a[0];
dest[1] += a[1];
dest[2] += a[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Make 'dest' the sum of vectors a and b.
@ -41,7 +41,7 @@ void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b) {
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
dest[2] = a[2] + b[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Multiply vector 'dest' by a
@ -50,7 +50,7 @@ void *vec3f_mul(Vec3f dest, f32 a)
dest[0] *= a;
dest[1] *= a;
dest[2] *= a;
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Copy vector src to dest
@ -58,7 +58,7 @@ void *vec3s_copy(Vec3s dest, Vec3s src) {
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Set vector 'dest' to (x, y, z)
@ -66,7 +66,7 @@ void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z) {
dest[0] = x;
dest[1] = y;
dest[2] = z;
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Add vector a to 'dest'
@ -74,7 +74,7 @@ void *vec3s_add(Vec3s dest, Vec3s a) {
dest[0] += a[0];
dest[1] += a[1];
dest[2] += a[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Make 'dest' the sum of vectors a and b.
@ -82,7 +82,7 @@ void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b) {
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
dest[2] = a[2] + b[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Make 'dest' the difference of vectors a and b.
@ -90,7 +90,7 @@ void *vec3f_dif(Vec3f dest, Vec3f a, Vec3f b) {
dest[0] = a[0] - b[0];
dest[1] = a[1] - b[1];
dest[2] = a[2] - b[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Convert short vector a to float vector 'dest'
@ -98,7 +98,7 @@ void *vec3s_to_vec3f(Vec3f dest, Vec3s a) {
dest[0] = a[0];
dest[1] = a[1];
dest[2] = a[2];
return &dest; //! warning: function returns address of local variable
return dest;
}
/**
@ -110,7 +110,7 @@ void *vec3f_to_vec3s(Vec3s dest, Vec3f a) {
dest[0] = a[0] + ((a[0] > 0) ? 0.5f : -0.5f);
dest[1] = a[1] + ((a[1] > 0) ? 0.5f : -0.5f);
dest[2] = a[2] + ((a[2] > 0) ? 0.5f : -0.5f);
return &dest; //! warning: function returns address of local variable
return dest;
}
/**
@ -122,7 +122,7 @@ void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c)
dest[0] = (b[1] - a[1]) * (c[2] - b[2]) - (c[1] - b[1]) * (b[2] - a[2]);
dest[1] = (b[2] - a[2]) * (c[0] - b[0]) - (c[2] - b[2]) * (b[0] - a[0]);
dest[2] = (b[0] - a[0]) * (c[1] - b[1]) - (c[0] - b[0]) * (b[1] - a[1]);
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Make vector 'dest' the cross product of vectors a and b.
@ -130,7 +130,7 @@ void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b) {
dest[0] = a[1] * b[2] - b[1] * a[2];
dest[1] = a[2] * b[0] - b[2] * a[0];
dest[2] = a[0] * b[1] - b[0] * a[1];
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Scale vector 'dest' so it has length 1
@ -141,7 +141,7 @@ void *vec3f_normalize(Vec3f dest) {
dest[0] *= invsqrt;
dest[1] *= invsqrt;
dest[2] *= invsqrt;
return &dest; //! warning: function returns address of local variable
return dest;
}
/// Get length of vector 'a'
@ -883,7 +883,7 @@ void anim_spline_init(struct MarioState* m, Vec4s *keyFrames) {
* Returns TRUE when the last point is reached, FALSE otherwise.
*/
s32 anim_spline_poll(struct MarioState* m, Vec3f result) {
Vec4f weights;
Vec4f weights = { 0 };
s32 i;
s32 hasEnded = FALSE;

View file

@ -303,6 +303,8 @@ static void stub_surface_load_1(void) {
* @param vertexIndices Helper which tells positions in vertexData to start reading vertices
*/
static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {
if (vertexData == NULL || vertexIndices == NULL || *vertexIndices == NULL) { return NULL; }
struct Surface *surface;
register s32 x1, y1, z1;
register s32 x2, y2, z2;
@ -594,9 +596,8 @@ u32 get_area_terrain_size(s16 *data) {
* boxes (water, gas, JRB fog).
*/
void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects) {
s16 terrainLoadType;
s16 *vertexData;
UNUSED s32 unused;
s16 terrainLoadType = 0;
s16 *vertexData = NULL;
// Initialize the data for this.
gEnvironmentRegions = NULL;

View file

@ -309,13 +309,15 @@ void unload_mario_area(void) {
}
void change_area(s32 index) {
s32 areaFlags = gCurrentArea->flags;
s32 areaFlags = (gCurrentArea != NULL) ? gCurrentArea->flags : 0;
if (gCurrAreaIndex != index) {
unload_area();
load_area(index);
if (gCurrentArea != NULL) {
gCurrentArea->flags = areaFlags;
}
for (int i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].marioObj->oActiveParticleFlags = 0;
}

View file

@ -1451,7 +1451,7 @@ s32 update_fixed_camera(struct Camera *c, Vec3f focus, UNUSED Vec3f pos) {
f32 focusFloorOff;
f32 goalHeight;
f32 ceilHeight;
f32 heightOffset;
f32 heightOffset = 0;
f32 distCamToFocus;
UNUSED u8 filler2[8];
f32 scaleToMario = 0.5f;
@ -4917,7 +4917,7 @@ void play_sound_if_cam_switched_to_lakitu_or_mario(void) {
* Handles input for radial, outwards radial, parallel tracking, and 8 direction mode.
*/
s32 radial_camera_input(struct Camera *c, UNUSED f32 unused) {
s16 dummy;
s16 dummy = 0;
if ((gCameraMovementFlags & CAM_MOVE_ENTERED_ROTATE_SURFACE) || !(gCameraMovementFlags & CAM_MOVE_ROTATE)) {
@ -5160,7 +5160,7 @@ s32 determine_dance_cutscene(UNUSED struct Camera *c) {
* @return `pullResult` or `pushResult` depending on Mario's door action
*/
u8 open_door_cutscene(u8 pullResult, u8 pushResult) {
s16 result;
s16 result = 0;
if (sMarioCamState->action == ACT_PULLING_DOOR) {
result = pullResult;
@ -11286,7 +11286,7 @@ struct CutsceneSplinePoint sCcmOutsideCreditsSplineFocus[] = {
void play_cutscene(struct Camera *c) {
UNUSED u32 pad[3];
UNUSED s16 unusedYawFocToMario;
s16 cutsceneDuration;
s16 cutsceneDuration = 0;
u8 oldCutscene;
unusedYawFocToMario = sAreaYaw;

View file

@ -520,10 +520,10 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro
s32 i;
s16 radius, pitch, yaw;
Vec3s vertex1;
Vec3s vertex2;
Vec3s vertex3;
Vec3s interpolatedVertices[3];
Vec3s vertex1 = { 0 };
Vec3s vertex2 = { 0 };
Vec3s vertex3 = { 0 };
Vec3s interpolatedVertices[3] = { 0 };
static Vec3s prevVertex1;
static Vec3s prevVertex2;

View file

@ -1818,12 +1818,12 @@ s8 gDialogCourseActNum = 1;
void render_dialog_entries(void) {
#ifdef VERSION_EU
s8 lowerBound;
s8 lowerBound = 0;
#endif
void **dialogTable;
struct DialogEntry *dialog;
#ifdef VERSION_US
s8 lowerBound;
s8 lowerBound = 0;
#endif
#ifdef VERSION_EU
gInGameLanguage = eu_get_language();

View file

@ -756,7 +756,7 @@ static void initiate_painting_warp_node(struct WarpNode *pWarpNode) {
* Check is Mario has entered a painting, and if so, initiate a warp.
*/
void initiate_painting_warp(void) {
if (gCurrentArea->paintingWarpNodes != NULL && gMarioState->floor != NULL) {
if (gCurrentArea != NULL && gCurrentArea->paintingWarpNodes != NULL && gMarioState->floor != NULL) {
struct WarpNode *pWarpNode = get_painting_warp_node();
if (pWarpNode != NULL) {

View file

@ -242,7 +242,7 @@ void update_mario_pos_for_anim(struct MarioState *m) {
* Finds the vertical translation from Mario's animation.
*/
s16 return_mario_anim_y_translation(struct MarioState *m) {
Vec3s translation;
Vec3s translation = { 0 };
find_mario_anim_flags_and_translation(m->marioObj, 0, translation);
return translation[1];

View file

@ -523,7 +523,7 @@ s32 act_backflip(struct MarioState *m) {
}
s32 act_freefall(struct MarioState *m) {
s32 animation;
s32 animation = 0;
if (m->input & INPUT_B_PRESSED) {
return set_mario_action(m, ACT_DIVE, 0);
@ -1033,7 +1033,7 @@ s32 act_burning_fall(struct MarioState *m) {
}
s32 act_crazy_box_bounce(struct MarioState *m) {
f32 minSpeed;
f32 minSpeed = 32;
if (m->actionTimer == 0) {
switch (m->actionArg) {

View file

@ -966,9 +966,9 @@ s32 act_unlocking_star_door(struct MarioState *m) {
}
s32 act_entering_star_door(struct MarioState *m) {
f32 targetDX;
f32 targetDZ;
s16 targetAngle;
f32 targetDX = 0;
f32 targetDZ = 0;
s16 targetAngle = 0;
if (m->actionTimer++ == 0) {
if (m->interactObj != NULL) {

View file

@ -166,6 +166,8 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
s16 facingDYaw;
struct Surface *floor = m->floor;
if (floor == NULL) { return; }
s16 slopeAngle = atan2s(floor->normal.z, floor->normal.x);
f32 steepness = sqrtf(floor->normal.x * floor->normal.x + floor->normal.z * floor->normal.z);
UNUSED f32 normalY = floor->normal.y;
@ -289,6 +291,7 @@ void apply_slope_accel(struct MarioState *m) {
f32 slopeAccel;
struct Surface *floor = m->floor;
if (floor == NULL) { return; }
f32 steepness = sqrtf(floor->normal.x * floor->normal.x + floor->normal.z * floor->normal.z);
UNUSED f32 normalY = floor->normal.y;
@ -380,7 +383,7 @@ void update_shell_speed(struct MarioState *m) {
m->forwardVel += 1.1f;
} else if (m->forwardVel <= targetSpeed) {
m->forwardVel += 1.1f - m->forwardVel / 58.0f;
} else if (m->floor->normal.y >= 0.95f) {
} else if (m->floor != NULL && m->floor->normal.y >= 0.95f) {
m->forwardVel -= 1.0f;
}
@ -456,7 +459,7 @@ void update_walking_speed(struct MarioState *m) {
m->forwardVel += 1.1f;
} else if (m->forwardVel <= targetSpeed) {
m->forwardVel += 1.1f - m->forwardVel / 43.0f;
} else if (m->floor->normal.y >= 0.95f) {
} else if (m->floor != NULL && m->floor->normal.y >= 0.95f) {
m->forwardVel -= 1.0f;
}

View file

@ -184,7 +184,7 @@ void play_anim_sound(struct MarioState *m, u32 actionState, s32 animFrame, u32 s
s32 act_start_sleeping(struct MarioState *m) {
#ifndef VERSION_JP
s32 animFrame;
s32 animFrame = 0;
#endif
if (check_common_idle_cancels(m)) {

View file

@ -1132,7 +1132,7 @@ static void update_metal_water_walking_speed(struct MarioState *m) {
m->forwardVel += 1.1f;
} else if (m->forwardVel <= val) {
m->forwardVel += 1.1f - m->forwardVel / 43.0f;
} else if (m->floor->normal.y >= 0.95f) {
} else if (m->floor != NULL && m->floor->normal.y >= 0.95f) {
m->forwardVel -= 1.0f;
}

View file

@ -860,7 +860,7 @@ Gfx *geo_movtex_draw_nocolor(s32 callContext, struct GraphNode *node, UNUSED Mat
*/
Gfx *geo_movtex_draw_colored(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx) {
s32 i;
s16 *movtexVerts;
s16 *movtexVerts = NULL;
struct GraphNodeGenerated *asGenerated;
Gfx *gfx = NULL;
@ -872,6 +872,7 @@ Gfx *geo_movtex_draw_colored(s32 callContext, struct GraphNode *node, UNUSED Mat
asGenerated->fnNode.node.flags =
(asGenerated->fnNode.node.flags & 0xFF) | (gMovtexColored[i].layer << 8);
movtexVerts = segmented_to_virtual(gMovtexColored[i].movtexVerts);
if (movtexVerts == NULL) { continue; }
update_moving_texture_offset(movtexVerts, MOVTEX_ATTR_COLORED_S);
gfx = movtex_gen_list(movtexVerts, &gMovtexColored[i], MOVTEX_LAYOUT_COLORED);
break;
@ -952,7 +953,7 @@ Gfx *geo_movtex_draw_colored_2_no_update(s32 callContext, struct GraphNode *node
* Note that the final TTC only has one big treadmill though.
*/
Gfx *geo_movtex_update_horizontal(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx) {
void *movtexVerts;
void *movtexVerts = NULL;
if (callContext == GEO_CONTEXT_RENDER) {
struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node;
@ -971,7 +972,9 @@ Gfx *geo_movtex_update_horizontal(s32 callContext, struct GraphNode *node, UNUSE
movtexVerts = segmented_to_virtual(ttc_movtex_tris_small_surface_treadmill);
break;
}
if (movtexVerts != NULL) {
update_moving_texture_offset(movtexVerts, MOVTEX_ATTR_COLORED_S);
}
}
return NULL;
}

View file

@ -454,7 +454,8 @@ s16 obj_angle_to_point(struct Object *obj, f32 pointX, f32 pointZ) {
s16 obj_turn_toward_object(struct Object *obj, struct Object *target, s16 angleIndex, s16 turnAmount) {
f32 a, b, c, d;
UNUSED s32 unused;
s16 targetAngle, startAngle;
s16 targetAngle = 0;
s16 startAngle = 0;
switch (angleIndex) {
case O_MOVE_ANGLE_PITCH_INDEX:
@ -1316,7 +1317,7 @@ void cur_obj_apply_drag_xz(f32 dragStrength) {
}
static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlopes) {
struct Surface *intendedFloor;
struct Surface *intendedFloor = NULL;
f32 intendedX = o->oPosX + o->oVelX;
f32 intendedZ = o->oPosZ + o->oVelZ;
@ -1350,7 +1351,7 @@ static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlop
// Don't walk off an edge
o->oMoveFlags |= OBJ_MOVE_HIT_EDGE;
return FALSE;
} else if (intendedFloor->normal.y > steepSlopeNormalY) {
} else if (intendedFloor != NULL && intendedFloor->normal.y > steepSlopeNormalY) {
// Allow movement onto a slope, provided it's not too steep
o->oPosX = intendedX;
o->oPosZ = intendedZ;
@ -1360,7 +1361,7 @@ static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlop
o->oMoveFlags |= OBJ_MOVE_HIT_EDGE;
return FALSE;
}
} else if ((ny = intendedFloor->normal.y) > steepSlopeNormalY || o->oPosY > intendedFloorHeight) {
} else if (intendedFloor != NULL && ((ny = intendedFloor->normal.y) > steepSlopeNormalY || o->oPosY > intendedFloorHeight)) {
// Allow movement upward, provided either:
// - The target floor is flat enough (e.g. walking up stairs)
// - We are above the target floor (most likely in the air)

View file

@ -703,7 +703,9 @@ void painting_generate_mesh(struct Painting *painting, s16 *mesh, s16 numTris) {
gPaintingMesh = mem_pool_alloc(gEffectsMemoryPool, numTris * sizeof(struct PaintingMeshVertex));
if (gPaintingMesh == NULL) {
return;
}
// accesses are off by 1 since the first entry is the number of vertices
for (i = 0; i < numTris; i++) {
gPaintingMesh[i].pos[0] = mesh[i * 3 + 1];
@ -735,7 +737,9 @@ void painting_calculate_triangle_normals(s16 *mesh, s16 numVtx, s16 numTris) {
gPaintingTriNorms = mem_pool_alloc(gEffectsMemoryPool, numTris * sizeof(Vec3f));
if (gPaintingTriNorms == NULL) {
return;
}
for (i = 0; i < numTris; i++) {
s16 tri = numVtx * 3 + i * 3 + 2; // Add 2 because of the 2 length entries preceding the list
s16 v0 = mesh[tri];
@ -864,6 +868,11 @@ Gfx *render_painting(u8 *img, s16 tWidth, s16 tHeight, s16 *textureMap, s16 mapV
Gfx *gfx = dlist;
if (verts == NULL || dlist == NULL) {
return NULL;
}
if (img == NULL) {
return NULL;
}
gLoadBlockTexture(gfx++, tWidth, tHeight, G_IM_FMT_RGBA, img);
@ -950,6 +959,7 @@ Gfx *painting_model_view_transform(struct Painting *painting) {
Gfx *gfx = dlist;
if (rotX == NULL || rotY == NULL || translate == NULL || dlist == NULL) {
return NULL;
}
guTranslate(translate, painting->posX, painting->posY, painting->posZ);
@ -1055,7 +1065,7 @@ Gfx *display_painting_rippling(struct Painting *painting) {
s16 *neighborTris = segmented_to_virtual(seg2_painting_mesh_neighbor_tris);
s16 numVtx = mesh[0];
s16 numTris = mesh[numVtx * 3 + 1];
Gfx *dlist;
Gfx *dlist = NULL;
// Generate the mesh and its lighting data
painting_generate_mesh(painting, mesh, numVtx);

View file

@ -201,7 +201,7 @@ f32 get_water_level_below_shadow(struct Shadow *s) {
* be dimmed based on its distance to the floor
*/
s8 init_shadow(struct Shadow *s, f32 xPos, f32 yPos, f32 zPos, s16 shadowScale, u8 overwriteSolidity) {
f32 waterLevel;
f32 waterLevel = 0;
f32 floorSteepness;
struct FloorGeometry *floorGeometry;
@ -312,7 +312,7 @@ void make_shadow_vertex_at_xyz(Vtx *vertices, s8 index, f32 relX, f32 relY, f32
vtxY += 5;
vtxZ += 5;
}
make_vertex(vertices, index, vtxX, vtxY, vtxZ, textureX << 5, textureY << 5, 255, 255, 255,
make_vertex(vertices, index, vtxX, vtxY, vtxZ, (u16)textureX << 5, (u16)textureY << 5, 255, 255, 255,
alpha // shadows are black
);
}

View file

@ -837,7 +837,7 @@ s32 is_newline(char c) {
/* 23CBA8 -> 23CCF0; orig name: func_8018E3D8 */
s32 gd_fread_line(char *buf, u32 size, struct GdFile *f) {
signed char c;
signed char c = 0;
u32 pos = 0;
UNUSED u32 pad1c;

View file

@ -657,7 +657,7 @@ void func_80190574(s32 a0, struct ObjJoint *a1, struct ObjJoint *a2, f32 x, f32
UNUSED u32 pad268;
UNUSED u32 sp264 = 0;
UNUSED u32 sp258[3]; // unused vec?
struct GdVec3f sp24C;
struct GdVec3f sp24C = { 0 };
struct GdVec3f sp240;
UNUSED u32 pad238[2];
s32 sp234; // i?

View file

@ -888,7 +888,7 @@ void gd_printf(const char *format, ...) {
UNUSED u32 pad150;
char buf[0x100]; // 50
char *csr = buf; // 4c
char spec[8]; // 44; goddard specifier string
char spec[8] = { 0 }; // 44; goddard specifier string
UNUSED u32 pad40;
union PrintVal val; // 38;
va_list args; // 34

View file

@ -745,8 +745,8 @@ void get_OBJ_shape(struct ObjShape *shape) {
s32 faceVtxIndex;
struct GdVec3f tempVec;
struct ObjFace *newFace;
struct ObjVertex *vtxArr[4000];
struct ObjFace *faceArr[4000];
struct ObjVertex *vtxArr[4000] = { 0 };
struct ObjFace *faceArr[4000] = { 0 };
s32 faceCount = 0;
s32 vtxCount = 0;
@ -1065,7 +1065,7 @@ struct GdFile *get_shape_from_file(struct ObjShape *shape, char *fileName) {
/* @ 247F78 for 0x69c; orig name: Unknown801997A8 */
struct ObjShape *make_grid_shape(enum ObjTypeFlag gridType, s32 a1, s32 a2, s32 a3, s32 a4) {
UNUSED u32 pad1074;
void *objBuf[32][32]; // vertex or particle depending on gridType
void *objBuf[32][32] = { 0 }; // vertex or particle depending on gridType
f32 sp70;
f32 sp6C;
f32 sp68;
@ -1156,13 +1156,17 @@ struct ObjShape *make_grid_shape(enum ObjTypeFlag gridType, s32 a1, s32 a2, s32
if (gridType == OBJ_TYPE_PARTICLES) {
for (parI = 0; parI <= a3; parI++) {
((struct ObjParticle *) objBuf[parI][0])->unk54 |= 2;
((struct ObjParticle *) objBuf[parI][a4])->unk54 |= 2;
struct ObjParticle* p1 = ((struct ObjParticle *) objBuf[parI][0]);
if (p1 != NULL) { p1->unk54 |= 2; }
struct ObjParticle* p2 = ((struct ObjParticle *) objBuf[parI][a4]);
if (p2 != NULL) { p2->unk54 |= 2; }
}
for (parI = 0; parI <= a4; parI++) {
((struct ObjParticle *) objBuf[0][parI])->unk54 |= 2;
((struct ObjParticle *) objBuf[a3][parI])->unk54 |= 2;
struct ObjParticle* p1 = ((struct ObjParticle *) objBuf[0][parI]);
if (p1 != NULL) { p1->unk54 |= 2; }
struct ObjParticle* p2 = ((struct ObjParticle *) objBuf[a3][parI]);
if (p2 != NULL) { p2->unk54 |= 2; }
}
}

View file

@ -207,7 +207,7 @@ s32 intro_play_its_a_me_mario(void) {
}
s32 lvl_intro_update(s16 arg1, UNUSED s32 arg2) {
s32 retVar;
s32 retVar = 0;
switch (arg1) {
case 0:

View file

@ -114,7 +114,7 @@ void bhv_act_selector_init(void) {
if (gCurrCourseNum == 0) { return; }
s16 i = 0;
s32 selectorModelIDs[10];
s32 selectorModelIDs[10] = { 0 };
u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1);
sVisibleStars = 0;

View file

@ -275,7 +275,7 @@ static u32 controller_sdl_rawkey(void) {
return ret;
}
for (int i = 0; i < MAX_MOUSEBUTTONS; ++i) {
for (u32 i = 1; i < MAX_MOUSEBUTTONS; ++i) {
if (last_mouse & SDL_BUTTON(i)) {
const u32 ret = VK_OFS_SDL_MOUSE + i;
last_mouse = 0;

View file

@ -310,7 +310,7 @@ static u32 controller_sdl_rawkey(void) {
return ret;
}
for (int i = 0; i < MAX_MOUSEBUTTONS; ++i) {
for (u32 i = 1; i < MAX_MOUSEBUTTONS; ++i) {
if (last_mouse & SDL_BUTTON(i)) {
const u32 ret = VK_OFS_SDL_MOUSE + i;
last_mouse = 0;

View file

@ -436,8 +436,12 @@ static bool pack_zip_seek(UNUSED void *pack, fs_file_t *file, const int64_t ofs)
if (inflateInit2(&zstream, -MAX_WBITS) != Z_OK)
return false;
// reset the underlying file handle back to the start
if (fseek(zipfile->fstream, ent->ofs, SEEK_SET) != 0)
if (fseek(zipfile->fstream, ent->ofs, SEEK_SET) != 0) {
if (zstream.zfree) {
zstream.zfree(zstream.opaque, zstream.state);
}
return false;
}
// free and replace the old one
inflateEnd(&zipfile->zstream);
memcpy(&zipfile->zstream, &zstream, sizeof(zstream));

View file

@ -627,7 +627,8 @@ static void gfx_opengl_init(void) {
if (!tex_cache) sys_fatal("out of memory allocating texture cache");
// check GL version
int vmajor, vminor;
int vmajor = 0;
int vminor = 0;
bool is_es = false;
gl_get_version(&vmajor, &vminor, &is_es);
if (vmajor < 2 && vminor < 1 && !is_es)

View file

@ -1239,7 +1239,7 @@ static void gfx_dp_load_block(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
SUPPORT_CHECK(ult == 0);
// The lrs field rather seems to be number of pixels to load
uint32_t word_size_shift;
uint32_t word_size_shift = 0;
switch (rdp.texture_to_load.siz) {
case G_IM_SIZ_4b:
word_size_shift = 0; // Or -1? It's unused in SM64 anyway.
@ -1267,7 +1267,7 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
SUPPORT_CHECK(uls == 0);
SUPPORT_CHECK(ult == 0);
uint32_t word_size_shift;
uint32_t word_size_shift = 0;
switch (rdp.texture_to_load.siz) {
case G_IM_SIZ_4b:
word_size_shift = 0; // Or -1? It's unused in SM64 anyway.
@ -1680,6 +1680,7 @@ static void gfx_run_dl(Gfx* cmd) {
{
int32_t lrx, lry, tile, ulx, uly;
uint32_t uls, ult, dsdx, dtdy;
tile = 0;
#ifdef F3DEX_GBI_2E
lrx = (int32_t)(C0(0, 24) << 8) >> 8;
lry = (int32_t)(C1(0, 24) << 8) >> 8;

View file

@ -186,11 +186,13 @@ static bool ns_discord_initialize(enum NetworkType networkType) {
}
// set up manager pointers
if (app.core != NULL) {
app.users = app.core->get_user_manager(app.core);
app.achievements = app.core->get_achievement_manager(app.core);
app.activities = app.core->get_activity_manager(app.core);
app.application = app.core->get_application_manager(app.core);
app.lobbies = app.core->get_lobby_manager(app.core);
}
// register launch params
register_launch_command();

View file

@ -1,10 +1,9 @@
#include "socket/socket.h"
#include <stdio.h>
#include "network.h"
#include "object_fields.h"
#include "object_constants.h"
#include "game/object_list_processor.h"
#include "behavior_table.h"
#include "socket/socket.h"
#ifdef DISCORD_SDK
#include "discord/discord.h"
#endif

View file

@ -91,7 +91,7 @@ static bool packet_read_lnt(struct Packet* p, struct LSTNetworkType* lnt) {
LOG_ERROR("received lua sync table with invalid value length: %d", valueLength);
return false;
}
lnt->value.string = calloc(valueLength + 1, sizeof(u8));
lnt->value.string = calloc(valueLength + 1, sizeof(char));
packet_read(p, lnt->value.string, valueLength * sizeof(u8));
return true;
}

View file

@ -104,7 +104,7 @@ void network_receive_mod_list(struct Packet* p) {
u16 nameLength = 0;
packet_read(p, &nameLength, sizeof(u16));
char* name = (char*)calloc(nameLength + 1, sizeof(u8));
char* name = (char*)calloc(nameLength + 1, sizeof(char));
packet_read(p, name, nameLength * sizeof(u8));
u16 size = 0;

View file

@ -1,5 +1,5 @@
#include <stdio.h>
#include "socket.h"
#include <stdio.h>
#include "pc/configfile.h"
#include "pc/debuglog.h"
#include "pc/djui/djui.h"

View file

@ -1,14 +1,14 @@
#ifndef SOCKET_H
#define SOCKET_H
#include "../network.h"
#ifdef WINSOCK
#include "socket_windows.h"
#else
#include "socket_linux.h"
#endif
#include "../network.h"
extern struct NetworkSystem gNetworkSystemSocket;
SOCKET socket_initialize(void);

View file

@ -1,6 +1,6 @@
#ifdef WINSOCK
#include <stdio.h>
#include "socket_windows.h"
#include <stdio.h>
#include "pc/debuglog.h"
SOCKET socket_initialize(void) {

View file

@ -107,8 +107,8 @@ static inline bool copy_userdata(const char *userdir) {
// also try to copy the config
path[len] = oldpath[len] = 0;
strncat(path, "/" CONFIGFILE_DEFAULT, sizeof(path) - 1);
strncat(oldpath, "/" CONFIGFILE_DEFAULT, sizeof(oldpath) - 1);
strncat(path, "/" CONFIGFILE_DEFAULT, SYS_MAX_PATH - 1);
strncat(oldpath, "/" CONFIGFILE_DEFAULT, SYS_MAX_PATH - 1);
fs_sys_copy_file(oldpath, path);
return ret;