Skip to content

Commit 6cbb5f4

Browse files
committed
Explicit casts to shut g++ warnings and errors
1 parent bbb0d2a commit 6cbb5f4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

opencl/common.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ char* common_read_file(const char *path, long *length_out) {
3737
fseek(f, 0, SEEK_END);
3838
length = ftell(f);
3939
fseek(f, 0, SEEK_SET);
40-
buffer = malloc(length);
40+
buffer = (char *)malloc(length);
4141
if (fread(buffer, 1, length, f) < (size_t)length) {
4242
return NULL;
4343
}
@@ -52,7 +52,7 @@ char* common_read_file_null(const char *path) {
5252
char *f;
5353
long length;
5454
f = common_read_file(path, &length);
55-
f = realloc(f, length + 1);
55+
f = (char *)realloc(f, length + 1);
5656
f[length] = '\0';
5757
return f;
5858
}
@@ -68,7 +68,7 @@ void common_build_program(
6868
ret = clBuildProgram(*program, 1, &(common->device), options, NULL, NULL);
6969
if (CL_SUCCESS != ret) {
7070
clGetProgramBuildInfo(*program, common->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &err_len);
71-
err = malloc(err_len);
71+
err = (char *)malloc(err_len);
7272
clGetProgramBuildInfo(*program, common->device, CL_PROGRAM_BUILD_LOG, err_len, err, NULL);
7373
fprintf(stderr, "error: clBuildProgram:\n%s\n", err);
7474
free(err);
@@ -195,7 +195,7 @@ void common_create_kernel_or_use_cache(
195195
} else {
196196
common_init_file(common, source_path);
197197
clGetProgramInfo(common->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &binary_size, NULL);
198-
binary = malloc(binary_size);
198+
binary = (char *)malloc(binary_size);
199199
clGetProgramInfo(common->program, CL_PROGRAM_BINARIES, binary_size, &binary, NULL);
200200
f = fopen(bin_path, "w");
201201
fwrite(binary, binary_size, 1, f);

opencl/interactive/vec_io.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int main(int argc, char **argv) {
9494
if (argc > a) {
9595
source_path = argv[a];
9696
} else {
97-
source_path = "vec_io.cl";
97+
source_path = (char *)"vec_io.cl";
9898
}
9999
a++;
100100
if (argc > a) {
@@ -106,13 +106,13 @@ int main(int argc, char **argv) {
106106
/* Initialize data. */
107107
n = 0;
108108
nmax = n + 1;
109-
io = malloc(nmax * sizeof(*io));
109+
io = (cl_float *)malloc(nmax * sizeof(*io));
110110
while(fscanf(input_vector_file, "%f", &f) != EOF) {
111111
io[n] = f;
112112
n++;
113113
if (n == nmax) {
114114
nmax *= 2;
115-
io = realloc(io, nmax * sizeof(*io));
115+
io = (cl_float *)realloc(io, nmax * sizeof(*io));
116116
}
117117
}
118118
io_sizeof = n * sizeof(*io);
@@ -121,7 +121,7 @@ int main(int argc, char **argv) {
121121
}
122122

123123
/* Create kernel. */
124-
common_create_kernel_or_use_cache(&common, use_cache, source_path, __FILE__ ".bin.tmp");
124+
common_create_kernel_or_use_cache(&common, use_cache, source_path, (char *)(__FILE__ ".bin.tmp"));
125125
buffer = clCreateBuffer(common.context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, io_sizeof, io, NULL);
126126
clSetKernelArg(common.kernel, 0, sizeof(buffer), &buffer);
127127
clEnqueueNDRangeKernel(common.command_queue, common.kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);

0 commit comments

Comments
 (0)