From c577ed1e84bc1b6137adcef459e18d5224c0e4aa Mon Sep 17 00:00:00 2001 From: zelda2774 <69368340+zelda2774@users.noreply.github.com> Date: Tue, 7 Sep 2021 18:13:52 +0200 Subject: [PATCH] Fix compiler warnings in z_camera/db_camera (#947) * Fix compiler warnings in z_camera/db_camera * review Co-authored-by: zelda2774 --- include/functions.h | 2 +- src/code/db_camera.c | 38 +++++++++++++++++++------------------- src/code/z_camera.c | 15 ++++++++++++--- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/include/functions.h b/include/functions.h index 22061c8ea4..90b44c1b9b 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1463,7 +1463,7 @@ void ShrinkWindow_Update(s32 updateRate); // ? DbCamera_PrintS16Bytes(?); // ? DbCamera_PrintCutBytes(?); void DbCamera_Init(DbCamera* dbCamera, Camera* cameraPtr); -// ? DbgCamera_Enable(?); +void DbgCamera_Enable(DbCamera* dbCamera, Camera* cam); void DbCamera_Update(DbCamera* dbCamera, Camera* cam); // ? DbCamera_GetFirstAvailableLetter(?); // ? DbCamera_InitCut(?); diff --git a/src/code/db_camera.c b/src/code/db_camera.c index 07ddcbbf73..b05f6d57ed 100644 --- a/src/code/db_camera.c +++ b/src/code/db_camera.c @@ -153,16 +153,16 @@ Vec3f* DbCamera_CalcUpFromPitchYawRoll(Vec3f* dest, s16 pitch, s16 yaw, s16 roll temp_f14 = 1.0f - cosNegRoll; cosPitchSinYaw = cosPitch * sinYaw; sp54 = SQ(cosPitchSinYaw); - sp4C = (cosPitchSinYaw * sinPitch) * (0, temp_f14); + sp4C = (cosPitchSinYaw * sinPitch) * ((void)0, temp_f14); cosPitchcosYaw = cosPitch * cosYaw; temp_f4_2 = ((1.0f - sp54) * cosNegRoll) + sp54; cosPitchCosYawSinRoll = cosPitchcosYaw * sinNegRoll; - temp_f6 = (cosPitchcosYaw * cosPitchSinYaw) * (0, temp_f14); + temp_f6 = (cosPitchcosYaw * cosPitchSinYaw) * ((void)0, temp_f14); temp_f10_2 = sinPitch * sinNegRoll; spA4.x = ((negSinPitchSinYaw * temp_f4_2) + (cosPitch * (sp4C - cosPitchCosYawSinRoll))) + (negSinPitchCosYaw * (temp_f6 + temp_f10_2)); sp54 = SQ(sinPitch); - temp_f4_2 = (sinPitch * cosPitchcosYaw) * (0, temp_f14); + temp_f4_2 = (sinPitch * cosPitchcosYaw) * ((void)0, temp_f14); temp_f8_3 = cosPitchSinYaw * sinNegRoll; temp_f8 = sp4C + cosPitchCosYawSinRoll; spA4.y = ((negSinPitchSinYaw * temp_f8) + (cosPitch * (((1.0f - sp54) * cosNegRoll) + sp54))) + @@ -544,21 +544,21 @@ void DbCamera_Init(DbCamera* dbCamera, Camera* cameraPtr) { dbCamera->unk_6C.z = 0; } -s32 DbgCamera_Enable(DbCamera* this, Camera* cam) { - this->at = cam->at; - this->eye = cam->eye; - this->unk_1C = cam->up; - this->fov = cam->fov; - this->roll = 0; - this->sub.nPoints = 1; - this->sub.unkIdx = 0; - this->sub.unk_08 = 0; - this->sub.unk_0A = 1; - this->sub.unk_0C = 1; - this->unk_78 = 0; - this->unk_7A = 0; - this->rollDegrees = 0.0f; - return func_800B4088(this, cam); +void DbgCamera_Enable(DbCamera* dbCamera, Camera* cam) { + dbCamera->at = cam->at; + dbCamera->eye = cam->eye; + dbCamera->unk_1C = cam->up; + dbCamera->fov = cam->fov; + dbCamera->roll = 0; + dbCamera->sub.nPoints = 1; + dbCamera->sub.unkIdx = 0; + dbCamera->sub.unk_08 = 0; + dbCamera->sub.unk_0A = 1; + dbCamera->sub.unk_0C = 1; + dbCamera->unk_78 = 0; + dbCamera->unk_7A = 0; + dbCamera->rollDegrees = 0.0f; + func_800B4088(dbCamera, cam); } #ifdef NON_EQUIVALENT @@ -1655,7 +1655,7 @@ s32 DbCamera_SaveCallback(char* c) { ret = Mempak_GetFileSize(2, *c); freeSize = Mempak_GetFreeBytes(2); - if (sAllocSize < (freeSize + ret)) { + if ((u32)sAllocSize < (freeSize + ret)) { if (!Mempak_Alloc(2, c, sAllocSize)) { return false; } diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 9f9eaf4fdb..473c096c57 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -7020,10 +7020,19 @@ void Camera_PrintSettings(Camera* camera) { if (camera->camDataIdx < 0) { sp50[i++] = '-'; } - if (camera->camDataIdx / 0xA != 0) { - sp50[i++] = i / 0xA + '0'; + + //! @bug: this code was clearly meaning to print `abs(camera->camDataIdx)` as a + //! one-or-two-digit number, instead of `i`. + // "sp50[i++] = ..." matches here, but is undefined behavior due to conflicting + // reads/writes between sequence points, triggering warnings. Work around by + // putting i++ afterwards while on the same line. + // clang-format off + if (camera->camDataIdx / 10 != 0) { + sp50[i] = i / 10 + '0'; i++; } - sp50[i++] = i % 10 + '0'; + sp50[i] = i % 10 + '0'; i++; + // clang-format on + sp50[i++] = ' '; sp50[i++] = ' '; sp50[i++] = ' ';