From 97d2b0146c141269bdbbb1192aeb157e47cc5d65 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 11 Jul 2026 16:22:05 +0200 Subject: [PATCH] REVIEWED: Replace `assert()` by runtime checks - ROS: `CLN-012` --- src/external/tinyobj_loader_c.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/external/tinyobj_loader_c.h b/src/external/tinyobj_loader_c.h index 88b2acbdc..8d077d665 100644 --- a/src/external/tinyobj_loader_c.h +++ b/src/external/tinyobj_loader_c.h @@ -1020,7 +1020,12 @@ static int parseLine(Command *command, const char *p, unsigned int p_len, int triangulate) { char linebuf[4096]; const char *token; - assert(p_len < 4095); + + // @raysan5: + // WARNING: If -DNDEBUG is set when compiling, assertions will not + // be present in the compiled binary, replacing by a runtime check + //assert(p_len < 4095); + if (p_len > 4095) return 0; memcpy(linebuf, p, p_len); linebuf[p_len] = '\0'; @@ -1102,8 +1107,12 @@ static int parseLine(Command *command, const char *p, unsigned int p_len, tinyobj_vertex_index_t i1; tinyobj_vertex_index_t i2 = f[1]; - assert(3 * num_f < TINYOBJ_MAX_FACES_PER_F_LINE); - + // @raysan5: + // WARNING: If -DNDEBUG is set when compiling, assertions will not + // be present in the compiled binary, replacing by a runtime check + //assert(3 * num_f < TINYOBJ_MAX_FACES_PER_F_LINE); + if (3*num_f > TINYOBJ_MAX_FACES_PER_F_LINE) return 0; + for (k = 2; k < num_f; k++) { i1 = i2; i2 = f[k]; @@ -1119,7 +1128,13 @@ static int parseLine(Command *command, const char *p, unsigned int p_len, } else { unsigned int k = 0; - assert(num_f < TINYOBJ_MAX_FACES_PER_F_LINE); + + // @raysan5: + // WARNING: If -DNDEBUG is set when compiling, assertions will not + // be present in the compiled binary, replacing by a runtime check + //assert(num_f < TINYOBJ_MAX_FACES_PER_F_LINE); + if (num_f > TINYOBJ_MAX_FACES_PER_F_LINE) return 0; + for (k = 0; k < num_f; k++) { command->f[k] = f[k]; }