Skip to content

Commit

Permalink
Fix more Clang-analyzer alerts (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
skejeton committed Apr 14, 2024
1 parent 38e70b5 commit be2275a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
12 changes: 0 additions & 12 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,18 +923,6 @@ umth_window_setup(UmkaStackSlot *p, UmkaStackSlot *r)
th_window_setup(title, w, h);
}

// draws text
void
umdrawtext(UmkaStackSlot *p, UmkaStackSlot *r)
{
fu size = p[0].real32Val;
uint32_t color = (uint32_t)p[1].uintVal;
th_vf2 pos = *(th_vf2 *)&p[2];
char *text = (char *)p[3].ptrVal;

th_canvas_text(text, color, pos, size);
}

void
umth_window_get_dimensions(UmkaStackSlot *p, UmkaStackSlot *r)
{
Expand Down
6 changes: 2 additions & 4 deletions src/collisions.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "tophat.h"

#define MIN(a, b) (a < b ? a : b)

// line to line is stolen from: http://jeffreythompson.org/collision-detection/table_of_contents.php
int
th_line_to_line(th_vf2 b1, th_vf2 e1, th_vf2 b2, th_vf2 e2, th_vf2 *ic1)
Expand Down Expand Up @@ -135,7 +133,7 @@ th_line_to_tilemap(th_vf2 b, th_vf2 e, th_tmap *t, th_vf2 *ic)
float lineLen = sqrt(mx * mx + my * my);
th_vector_normalize(&mx, &my);

float x = b.x, y = b.y, minlen = -1;
float x = b.x, y = b.y, minlen = FLT_MAX;
bool coll = false;
float len = 0;
while (len < lineLen) {
Expand All @@ -146,7 +144,7 @@ th_line_to_tilemap(th_vf2 b, th_vf2 e, th_tmap *t, th_vf2 *ic)
if (x >= t->pos.x && y >= t->pos.y && tx < tw && ty < th && tile >= 0 &&
t->collmask.data[tile]) {
coll = true;
if (minlen == -1 || len < minlen)
if (len < minlen)
minlen = len;
}

Expand Down
6 changes: 4 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ th_main(int argc, char *argv[])
th_regularize_path(scriptpath, "./", regularizedScriptPath, sizeof regularizedScriptPath);
th_regularize_path(respath, "./", thg->respath, sizeof thg->respath);

if (thg->respath[strlen(thg->respath) - 1] != '/' && thg->respath[0] != 0) {
if (strlen(thg->respath) == sizeof(thg->respath) - 1) {
size_t respath_len = strlen(thg->respath);

if (respath_len > 0 && thg->respath[respath_len - 1] != '/' && thg->respath[0] != 0) {
if (respath_len == sizeof(thg->respath) - 1) {
th_error("Respath is too long");
return 1;
}
Expand Down
13 changes: 8 additions & 5 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ th_rotate_point(th_vf2 *p, th_vf2 o, fu rot)
void
th_vector_normalize(float *x, float *y)
{
if (fabs(*x) > fabs(*y)) {
*y /= fabs(*x);
*x /= fabs(*x);
float fx = fabs(*x);
float fy = fabs(*y);

if (fx > fy) {
*x /= fx;
*y /= fx;
} else {
*x /= fabs(*y);
*y /= fabs(*y);
*x /= fy;
*y /= fy;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ th_print_umka_error_and_quit(int code)

if (!umkaGetCallStack(
thg->umka, depth, MSG_LEN + 1, &offset, file, fnName, &line)) {
break;
fprintf(stderr, "\t\t...\n");
break;
}
#ifndef _WIN32
fprintf(stderr, "\033[34m");
Expand Down

0 comments on commit be2275a

Please sign in to comment.