Skip to content

Commit ea7cc30

Browse files
committed
tests/type_confusion: make Dav1dContext opaque (like it is in dav1d)
1 parent 3c0ac0e commit ea7cc30

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

tests/type_confusion/dav1d.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ RUN: cat dav1d_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s
88
#define IA2_COMPARTMENT 2
99
#include <ia2_compartment_init.inc>
1010

11+
struct Dav1dContext {
12+
int field;
13+
};
14+
15+
const size_t DAV1D_CONTEXT_SIZE = sizeof(Dav1dContext);
16+
1117
/// Allocate memory in dav1d's compartment 2.
1218
void* dav1d_alloc(const size_t size) {
1319
return malloc(size);

tests/type_confusion/include/dav1d.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include <stddef.h>
44

5-
typedef struct {
6-
int field;
7-
} Dav1dContext;
5+
typedef struct Dav1dContext Dav1dContext;
6+
7+
extern const size_t DAV1D_CONTEXT_SIZE;
88

99
typedef struct Dav1dSettings {
1010
int field;

tests/type_confusion/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ INIT_RUNTIME(2);
1515
#include <ia2_compartment_init.inc>
1616

1717
Test(type_confusion, normal) {
18-
Dav1dContext *c = dav1d_alloc(sizeof(Dav1dContext));
18+
// `Dav1dContext` is opaque.
19+
Dav1dContext *c = dav1d_alloc(DAV1D_CONTEXT_SIZE);
1920
Dav1dSettings *settings = dav1d_alloc(sizeof(Dav1dSettings));
2021
Dav1dPicture *pic = dav1d_alloc(sizeof(Dav1dPicture));
2122

@@ -29,8 +30,8 @@ Test(type_confusion, normal) {
2930
}
3031

3132
Test(type_confusion, uninitialized, .signal = SIGABRT) {
32-
Dav1dContext *c = dav1d_alloc(sizeof(Dav1dContext));
33-
Dav1dContext *c2 = dav1d_alloc(sizeof(Dav1dContext));
33+
Dav1dContext *c = dav1d_alloc(DAV1D_CONTEXT_SIZE);
34+
Dav1dContext *c2 = dav1d_alloc(DAV1D_CONTEXT_SIZE);
3435
Dav1dSettings *settings = dav1d_alloc(sizeof(Dav1dSettings));
3536
Dav1dPicture *pic = dav1d_alloc(sizeof(Dav1dPicture));
3637

@@ -46,7 +47,7 @@ Test(type_confusion, uninitialized, .signal = SIGABRT) {
4647
}
4748

4849
Test(type_confusion, wrong_type, .signal = SIGABRT) {
49-
Dav1dContext *c = dav1d_alloc(sizeof(Dav1dContext));
50+
Dav1dContext *c = dav1d_alloc(DAV1D_CONTEXT_SIZE);
5051
Dav1dSettings *settings = dav1d_alloc(sizeof(Dav1dSettings));
5152
Dav1dPicture *pic = dav1d_alloc(sizeof(Dav1dPicture));
5253

@@ -61,7 +62,7 @@ Test(type_confusion, wrong_type, .signal = SIGABRT) {
6162
}
6263

6364
Test(type_confusion, null, .signal = SIGABRT) {
64-
Dav1dContext *c = dav1d_alloc(sizeof(Dav1dContext));
65+
Dav1dContext *c = dav1d_alloc(DAV1D_CONTEXT_SIZE);
6566
Dav1dSettings *settings = dav1d_alloc(sizeof(Dav1dSettings));
6667
Dav1dPicture *pic = dav1d_alloc(sizeof(Dav1dPicture));
6768

@@ -76,7 +77,7 @@ Test(type_confusion, null, .signal = SIGABRT) {
7677
}
7778

7879
Test(type_confusion, use_after_free, .signal = SIGABRT) {
79-
Dav1dContext *c = dav1d_alloc(sizeof(Dav1dContext));
80+
Dav1dContext *c = dav1d_alloc(DAV1D_CONTEXT_SIZE);
8081
Dav1dSettings *settings = dav1d_alloc(sizeof(Dav1dSettings));
8182
Dav1dPicture *pic = dav1d_alloc(sizeof(Dav1dPicture));
8283

0 commit comments

Comments
 (0)