Skip to content

Commit 66ef196

Browse files
quarthexMrAnno
authored andcommitted
fix: allow asserting pointers to const data
1 parent 71dbf85 commit 66ef196

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/criterion/internal/assert/tag.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129

130130
#define CRI_ASSERT_TEST_TAG_ptr ,
131131
#define CRI_ASSERT_TEST_TAGC_ptr() ,
132-
#define CRI_ASSERT_TYPE_TAG_ptr void *,
132+
#define CRI_ASSERT_TYPE_TAG_ptr const void *,
133133
#define CRI_ASSERT_TYPE_TAG_ID_ptr ptr,
134134

135135
#define CRI_ASSERT_TEST_TAG_str ,
@@ -311,7 +311,7 @@ static inline char *CRI_USER_TAG_ID(tostr, uptr)(const uintptr_t *e)
311311
return str;
312312
}
313313

314-
static inline char *CRI_USER_TAG_ID(tostr, ptr)(void **e)
314+
static inline char *CRI_USER_TAG_ID(tostr, ptr)(const void **e)
315315
{
316316
char *str = NULL;
317317
cr_asprintf(&str, "0x%" CRI_PRIxPTR, (uintptr_t) *e);

test/full/bug521.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
#include <criterion/new/assert.h>
33

44
Test(bug521, str) {
5-
static const char *foo = "foo";
5+
static const char *const foo = "foo";
66
cr_assert(eq(str, foo, "foo"));
77
cr_assert(ne(str, foo, "oof"));
88
}
99

1010
Test(bug521, wcs) {
11-
static const wchar_t *foo = L"foo";
11+
static const wchar_t *const foo = L"foo";
1212
cr_assert(eq(wcs, foo, L"foo"));
1313
cr_assert(ne(wcs, foo, L"oof"));
14+
}
15+
16+
Test(bug521, ptr) {
17+
static const char *const foo = "foo";
18+
cr_assert(eq(ptr, foo, foo));
1419
}

0 commit comments

Comments
 (0)