Skip to content

Commit 9306b96

Browse files
committed
Fix bug in key_read and explain KERNEL_KEY_MM.
1 parent e1bd3c8 commit 9306b96

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/gpuarray_buffer_cuda.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef struct _kernel_key {
5959
strb src;
6060
} kernel_key;
6161

62+
/* Size of the kernel_key that we can memcopy to duplicate */
6263
#define KERNEL_KEY_MM (sizeof(kernel_key) - sizeof(strb))
6364

6465
static void key_free(cache_key_t _k) {
@@ -100,12 +101,16 @@ static kernel_key *key_read(const strb *b) {
100101
if (b->l < KERNEL_KEY_MM) return NULL;
101102
k = calloc(1, sizeof(*k));
102103
if (k == NULL) return NULL;
104+
memcpy(k, b->s, KERNEL_KEY_MM);
105+
if (k->version != 0) {
106+
free(k);
107+
return NULL;
108+
}
103109
if (strb_ensure(&k->src, b->l - KERNEL_KEY_MM) != 0) {
104110
strb_clear(&k->src);
105111
free(k);
106112
return NULL;
107113
}
108-
memcpy(k->bin_id, b->s, KERNEL_KEY_MM);
109114
strb_appendn(&k->src, b->s + KERNEL_KEY_MM, b->l - KERNEL_KEY_MM);
110115
return k;
111116
}

0 commit comments

Comments
 (0)