Skip to content

Commit 7cb8b3c

Browse files
committed
clar(clar__assert_equal): do in-bounds check before accessing element
When accessing an array element (or, in these instances, characters in a string), the check whether the array index is within bounds should always come before accessing said element. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7130e62 commit 7cb8b3c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

t/unit-tests/clar/clar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ void clar__assert_equal(
767767
if (!is_equal) {
768768
if (s1 && s2) {
769769
int pos;
770-
for (pos = 0; s1[pos] == s2[pos] && pos < len; ++pos)
770+
for (pos = 0; pos < len && s1[pos] == s2[pos]; ++pos)
771771
/* find differing byte offset */;
772772
p_snprintf(buf, sizeof(buf), "'%.*s' != '%.*s' (at byte %d)",
773773
len, s1, len, s2, pos);
@@ -803,7 +803,7 @@ void clar__assert_equal(
803803
if (!is_equal) {
804804
if (wcs1 && wcs2) {
805805
int pos;
806-
for (pos = 0; wcs1[pos] == wcs2[pos] && pos < len; ++pos)
806+
for (pos = 0; pos < len && wcs1[pos] == wcs2[pos]; ++pos)
807807
/* find differing byte offset */;
808808
p_snprintf(buf, sizeof(buf), "'%.*ls' != '%.*ls' (at byte %d)",
809809
len, wcs1, len, wcs2, pos);

0 commit comments

Comments
 (0)