Skip to content

Commit 6fbe8fd

Browse files
committed
Orb verify_casson: rewriting function to fix various issues: an unjustified early out and if-branches based on uninitialized memory.
1 parent e352329 commit 6fbe8fd

1 file changed

Lines changed: 26 additions & 36 deletions

File tree

src/snappy/extensions/Orb/kernel/unix_kit/casson_io.c

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -331,49 +331,39 @@ static Boolean verify_casson(CassonFormat *cf)
331331
return FALSE;
332332
}
333333

334-
for (int i = 0; i < cf->num_tet; i++) {
335-
Boolean check[4][4];
336-
for (int j = 0; j < 4; j++) {
337-
for (int k = 0; k < 4; k++) {
338-
check[j][k] = j == k;
334+
Boolean * tet_edges = NEW_ARRAY(6 * cf->num_tet, Boolean);
339335

340-
EdgeInfo * ei = cf->head;
341-
342-
if (ei == NULL) {
343-
uFatalError("verify_casson 1", "casson_io.c");
344-
return FALSE;
345-
}
346-
347-
while (ei != NULL) {
348-
TetEdgeInfo * tei = ei->head;
349-
350-
if (tei == NULL) {
351-
uFatalError("verify_casson 2", "casson_io.c");
352-
return FALSE;
353-
}
354-
355-
while (tei != NULL) {
356-
if (tei->tet_index == i) {
357-
if (check[tei->f1][tei->f2]) return TRUE;
336+
for (int i = 0; i < 6 * cf->num_tet; i++) {
337+
tet_edges[i] = FALSE;
338+
}
358339

359-
check[tei->f1][tei->f2] = TRUE;
360-
check[tei->f2][tei->f1] = TRUE;
361-
}
362-
tei = tei->next;
363-
}
364-
ei = ei->next;
365-
}
340+
for (EdgeInfo * ei = cf->head; ei != NULL; ei = ei->next) {
341+
if (ei->head == NULL) {
342+
uFatalError("verify_casson 1", "cassion_io.c");
343+
my_free(tet_edges);
344+
return FALSE;
345+
}
366346

367-
for (int j = 0; j < 4; j++)
368-
for (int k = 0; k < 4; k++)
369-
if (check[j][k] == FALSE) {
370-
uFatalError("verify_casson 3", "casson_io.c");
371-
return FALSE;
372-
}
347+
for (TetEdgeInfo * tei = ei->head; tei != NULL; tei = tei->next) {
348+
if (tei->f1 == tei->f2) {
349+
uFatalError("verify_casson 2", "cassion_io.c");
350+
my_free(tet_edges);
351+
return FALSE;
373352
}
353+
354+
int i = 6 * tei->tet_index + edge_between_faces[tei->f1][tei->f2];
355+
tet_edges[i] = TRUE;
374356
}
375357
}
376358

359+
for (int i = 0; i < 6 * cf->num_tet; i++) {
360+
if (tet_edges[i] == FALSE) {
361+
my_free(tet_edges);
362+
return FALSE;
363+
}
364+
}
365+
366+
my_free(tet_edges);
377367
return TRUE;
378368
}
379369

0 commit comments

Comments
 (0)