Skip to content

Commit 0b2dcda

Browse files
jenshannoschwalmTurboGit
authored andcommitted
Another round of removing double casted malloc/calloc
Avoid double casting in more malloc() calloc() calls where appropriate. Some formatting
1 parent fe8537a commit 0b2dcda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+154
-162
lines changed

src/common/bilateral.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ dt_bilateral_t *dt_bilateral_init(const int width, // width of input image
175175
const float sigma_s, // spatial sigma (blur pixel coords)
176176
const float sigma_r) // range sigma (blur luma values)
177177
{
178-
dt_bilateral_t *b = (dt_bilateral_t *)malloc(sizeof(dt_bilateral_t));
178+
dt_bilateral_t *b = malloc(sizeof(dt_bilateral_t));
179179
if(!b) return NULL;
180180
dt_bilateral_grid_size(b,width,height,100.0f,sigma_s,sigma_r);
181181
b->width = width;
@@ -222,7 +222,7 @@ void dt_bilateral_splat(const dt_bilateral_t *b, const float *const in)
222222
oz + oy + ox
223223
};
224224

225-
DT_OMP_FOR()
225+
DT_OMP_FOR()
226226
for(int slice = 0; slice < b->numslices; slice++)
227227
{
228228
const int firstrow = slice * b->sliceheight;

src/common/colorspaces.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ dt_colorspaces_t *dt_colorspaces_init()
13961396
{
13971397
cmsSetLogErrorHandler(cms_error_handler);
13981398

1399-
dt_colorspaces_t *res = (dt_colorspaces_t *)calloc(1, sizeof(dt_colorspaces_t));
1399+
dt_colorspaces_t *res = calloc(1, sizeof(dt_colorspaces_t));
14001400

14011401
_compute_prequantized_primaries(&D65xyY, &Rec709_Primaries,
14021402
&Rec709_Primaries_Prequantized);

src/common/curve_tools.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ float *d3_np_fs(int n, float a[], float b[])
107107
return NULL;
108108
}
109109
}
110-
float *x = (float *)calloc(n, sizeof(float));
110+
float *x = calloc(n, sizeof(float));
111111
// nc_merror(x, "d3_np_fs");
112112

113113
for(int i = 0; i < n; i++)
@@ -265,9 +265,9 @@ static float *spline_cubic_set_internal(int n, float t[], float y[], int ibcbeg,
265265
return NULL;
266266
}
267267
}
268-
float *a = (float *)calloc(3 * n, sizeof(float));
268+
float *a = calloc(3 * n, sizeof(float));
269269
// nc_merror(a, "spline_cubic_set");
270-
float *b = (float *)calloc(n, sizeof(float));
270+
float *b = calloc(n, sizeof(float));
271271
// nc_merror(b, "spline_cubic_set");
272272
//
273273
// Set up the first equation.
@@ -410,9 +410,9 @@ float *monotone_hermite_set(int n, float x[], float y[])
410410
}
411411
}
412412

413-
float *delta = (float *)calloc(n, sizeof(float));
413+
float *delta = calloc(n, sizeof(float));
414414
// nc_merror(delta, "spline_cubic_set");
415-
float *m = (float *)calloc(n + 1, sizeof(float));
415+
float *m = calloc(n + 1, sizeof(float));
416416
// nc_merror(m, "spline_cubic_set");
417417
// calculate the slopes
418418
for(int i = 0; i < n - 1; i++)
@@ -484,7 +484,7 @@ float *catmull_rom_set(int n, float x[], float y[])
484484
}
485485
}
486486
// nc_merror(delta, "spline_cubic_set");
487-
float *m = (float *)calloc(n, sizeof(float));
487+
float *m = calloc(n, sizeof(float));
488488
// nc_merror(m, "spline_cubic_set");
489489

490490
// calculate the slopes

src/common/dlopencl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dt_dlopencl_t *dt_dlopencl_init(const char *name)
8686
return NULL;
8787

8888
/* now bind symbols */
89-
ocl = (dt_dlopencl_t *)malloc(sizeof(dt_dlopencl_t));
89+
ocl = malloc(sizeof(dt_dlopencl_t));
9090

9191
if(ocl == NULL)
9292
{

src/common/dynload.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dt_gmodule_t *dt_gmodule_open(const char *library)
5757

5858
if(gmodule != NULL)
5959
{
60-
module = (dt_gmodule_t *)malloc(sizeof(dt_gmodule_t));
60+
module = malloc(sizeof(dt_gmodule_t));
6161
module->gmodule = gmodule;
6262
module->library = name;
6363
}
@@ -72,7 +72,7 @@ dt_gmodule_t *dt_gmodule_open(const char *library)
7272
gboolean dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void (**pointer)(void))
7373
{
7474
// As in g_module_symbol() reference the returned pointer might be NULL
75-
// so we also check for a non-NULL pointer for returned success
75+
// so we also check for a non-NULL pointer for returned success
7676
const gboolean symbol = g_module_symbol(module->gmodule, name, (gpointer)pointer);
7777
const gboolean valid = *pointer != NULL;
7878
if(!(symbol && valid))
@@ -95,7 +95,7 @@ dt_gmodule_t *dt_gmodule_open(const char *library)
9595

9696
if(gmodule != NULL)
9797
{
98-
module = (dt_gmodule_t *)malloc(sizeof(dt_gmodule_t));
98+
module = malloc(sizeof(dt_gmodule_t));
9999
module->gmodule = gmodule;
100100
module->library = g_strdup(library);
101101
}

src/common/film.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ char *dt_sqlite3_escape_wildcards(const char *s)
102102
if (*t == '%' || *t == '_' || *t == '~')
103103
count++;
104104
}
105-
char *result = (char*)malloc(count+1);
105+
char *result = malloc(count+1);
106106
if(!result)
107107
return result;
108108
char *dest = result;

src/common/gaussian.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ dt_gaussian_t *dt_gaussian_init(const int width, // width of input image
171171
g->sigma = sigma;
172172
g->order = order;
173173
g->buf = NULL;
174-
g->max = (float *)calloc(channels, sizeof(float));
175-
g->min = (float *)calloc(channels, sizeof(float));
174+
g->max = calloc(channels, sizeof(float));
175+
g->min = calloc(channels, sizeof(float));
176176

177177
if(!g->min || !g->max) goto error;
178178

@@ -828,8 +828,8 @@ dt_gaussian_cl_t *dt_gaussian_init_cl(const int devid,
828828
g->order = order;
829829
g->dev_temp1 = NULL;
830830
g->dev_temp2 = NULL;
831-
g->max = (float *)calloc(channels, sizeof(float));
832-
g->min = (float *)calloc(channels, sizeof(float));
831+
g->max = calloc(channels, sizeof(float));
832+
g->min = calloc(channels, sizeof(float));
833833

834834
if(!g->min || !g->max) goto error;
835835

src/common/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void heap_cleanup(heap_t *h)
4141

4242
heap_t *heap_init(uint32_t size)
4343
{
44-
heap_t *h = (heap_t *)malloc(sizeof(heap_t));
44+
heap_t *h = malloc(sizeof(heap_t));
4545
if(h)
4646
{
4747
h->keys = (uint64_t *)malloc(sizeof(uint64_t) * size);

src/common/l10n.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ gchar *_l10n_get_language(const gchar *filename)
328328

329329
dt_l10n_t *dt_l10n_init(const gchar *filename, const gboolean init_list)
330330
{
331-
dt_l10n_t *result = (dt_l10n_t *)calloc(1, sizeof(dt_l10n_t));
331+
dt_l10n_t *result = calloc(1, sizeof(dt_l10n_t));
332332
result->selected = -1;
333333
result->sys_default = -1;
334334

@@ -386,7 +386,7 @@ dt_l10n_t *dt_l10n_init(const gchar *filename, const gboolean init_list)
386386
"LC_MESSAGES", GETTEXT_PACKAGE ".mo", NULL);
387387
if(g_file_test(testname, G_FILE_TEST_EXISTS))
388388
{
389-
language = (dt_l10n_language_t *)calloc(1, sizeof(dt_l10n_language_t));
389+
language = calloc(1, sizeof(dt_l10n_language_t));
390390
result->languages = g_list_prepend(result->languages, language);
391391

392392
// some languages have a regional part in the filename, we

src/common/opencl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ int dt_opencl_lock_device(const int pipetype)
19661966
dt_pthread_mutex_lock(&cl->lock);
19671967

19681968
const size_t prio_size = sizeof(int) * (cl->num_devs + 1);
1969-
int *priority = (int *)malloc(prio_size);
1969+
int *priority = malloc(prio_size);
19701970
int mandatory;
19711971
gboolean heavy = FALSE;
19721972

@@ -2110,7 +2110,7 @@ static void _opencl_md5sum(const char **files,
21102110
}
21112111

21122112
const size_t filesize = filestat.st_size;
2113-
char *file = (char *)malloc(filesize);
2113+
char *file = malloc(filesize);
21142114

21152115
if(!file)
21162116
{
@@ -2177,7 +2177,7 @@ static gboolean _opencl_load_program(const int dev,
21772177
if(!f) return FALSE;
21782178

21792179
const size_t filesize = filestat.st_size;
2180-
char *file = (char *)malloc(filesize + 2048);
2180+
char *file = malloc(filesize + 2048);
21812181
size_t rd = fread(file, sizeof(char), filesize, f);
21822182
fclose(f);
21832183
if(rd != filesize)
@@ -2254,7 +2254,7 @@ static gboolean _opencl_load_program(const int dev,
22542254
// md5sum matches, load cached binary
22552255
size_t cached_filesize = cachedstat.st_size;
22562256

2257-
unsigned char *cached_content = (unsigned char *)malloc(cached_filesize + 1);
2257+
unsigned char *cached_content = malloc(cached_filesize + 1);
22582258
rd = fread(cached_content, sizeof(char), cached_filesize, cached);
22592259
if(rd != cached_filesize)
22602260
{

src/common/pdf.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static size_t _pdf_stream_encoder_Flate(dt_pdf_t *pdf, const unsigned char *data
277277
{
278278
int result;
279279
uLongf destLen = compressBound(len);
280-
unsigned char *buffer = (unsigned char *)malloc(destLen);
280+
unsigned char *buffer = malloc(destLen);
281281

282282
result = compress(buffer, &destLen, data, len);
283283

@@ -785,12 +785,12 @@ float * read_ppm(const char * filename, int * wd, int * ht)
785785
return NULL;
786786
}
787787

788-
float *image = (float*)malloc(sizeof(float) * width * height * 3);
788+
float *image = malloc(sizeof(float) * width * height * 3);
789789

790790
if(max <= 255)
791791
{
792792
// read a 8 bit PPM
793-
uint8_t *tmp = (uint8_t *)malloc(sizeof(uint8_t) * width * height * 3);
793+
uint8_t *tmp = malloc(sizeof(uint8_t) * width * height * 3);
794794
int res = fread(tmp, sizeof(uint8_t) * 3, width * height, f);
795795
if(res != width * height)
796796
{
@@ -809,7 +809,7 @@ float * read_ppm(const char * filename, int * wd, int * ht)
809809
else
810810
{
811811
// read a 16 bit PPM
812-
uint16_t *tmp = (uint16_t *)malloc(sizeof(uint16_t) * width * height * 3);
812+
uint16_t *tmp = malloc(sizeof(uint16_t) * width * height * 3);
813813
int res = fread(tmp, sizeof(uint16_t) * 3, width * height, f);
814814
if(res != width * height)
815815
{
@@ -871,7 +871,7 @@ int main(int argc, char *argv[])
871871
int width, height;
872872
float *image = read_ppm(argv[i + 1], &width, &height);
873873
if(!image) exit(1);
874-
uint16_t *data = (uint16_t *)malloc(sizeof(uint16_t) * 3 * width * height);
874+
uint16_t *data = malloc(sizeof(uint16_t) * 3 * width * height);
875875
if(!data)
876876
{
877877
free(image);

src/common/printprof.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int dt_apply_printer_profile(void **in, uint32_t width, uint32_t height, int bpp
6565
return 1;
6666
}
6767

68-
void *out = (void *)malloc((size_t)3 * width * height);
68+
void *out = malloc((size_t)3 * width * height);
6969

7070
if(bpp == 8)
7171
{

src/common/pwstorage/backend_apple_keychain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static char* _CFStringCopyUTF8String(CFStringRef aString) {
3030

3131
CFIndex length = CFStringGetLength(aString);
3232
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
33-
char *buffer = (char *)malloc(maxSize);
33+
char *buffer = malloc(maxSize);
3434
if (CFStringGetCString(aString, buffer, maxSize, kCFStringEncodingUTF8))
3535
{
3636
return buffer;

src/common/pwstorage/backend_kwallet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static gchar *array2string(const gchar *pos, guint *length)
438438
pos += sizeof(gint);
439439
guint j;
440440

441-
gunichar2 *tmp_string = (gunichar2 *)malloc(*length);
441+
gunichar2 *tmp_string = malloc(*length);
442442
memcpy(tmp_string, pos, *length);
443443

444444
for(j = 0; j < ((*length) / sizeof(gunichar2)); j++)

src/common/styles.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ void dt_styles_apply_style_item(dt_develop_t *dev,
669669

670670
if(mod_src)
671671
{
672-
dt_iop_module_t *module = (dt_iop_module_t *)calloc(1, sizeof(dt_iop_module_t));
672+
dt_iop_module_t *module = calloc(1, sizeof(dt_iop_module_t));
673673

674674
if(module)
675675
module->dev = dev;

src/common/utility.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ gchar *dt_util_float_to_str(const gchar *format, const double value)
139139
#endif
140140

141141
gchar *txt = g_strdup_printf(format, value);
142-
142+
143143
#if defined(WIN32)
144144
_configthreadlocale(_DISABLE_PER_THREAD_LOCALE);
145145
#else
@@ -490,7 +490,7 @@ static cairo_surface_t *_util_get_svg_img(gchar *logo, const float size)
490490
final_height = dimension.height * factor * ppd;
491491
const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, final_width);
492492

493-
guint8 *image_buffer = (guint8 *)calloc(stride * final_height, sizeof(guint8));
493+
guint8 *image_buffer = calloc(stride * final_height, sizeof(guint8));
494494
if(darktable.gui)
495495
surface = dt_cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_ARGB32, final_width,
496496
final_height, stride);
@@ -906,7 +906,7 @@ char *dt_read_file(const char *const filename, size_t *filesize)
906906
const size_t end = ftell(fd);
907907
rewind(fd);
908908

909-
char *content = (char *)malloc(sizeof(char) * end);
909+
char *content = malloc(sizeof(char) * end);
910910
if(!content) return NULL;
911911

912912
const size_t count = fread(content, sizeof(char), end, fd);

src/control/crawler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ GList *dt_control_crawler_run(void)
228228
while((c > image_path) && (*c != '.')) c--;
229229
len = c - image_path + 1;
230230

231-
char *extra_path = (char *)calloc(len + 3 + 1, sizeof(char));
231+
char *extra_path = calloc(len + 3 + 1, sizeof(char));
232232
if(extra_path)
233233
{
234234
g_strlcpy(extra_path, image_path, len + 1);

src/control/jobs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void *dt_control_job_get_params(const _dt_job_t *job)
132132
dt_job_t *dt_control_job_create(dt_job_execute_callback execute,
133133
const char *msg, ...)
134134
{
135-
_dt_job_t *job = (_dt_job_t *)calloc(1, sizeof(_dt_job_t));
135+
_dt_job_t *job = calloc(1, sizeof(_dt_job_t));
136136
if(!job) return NULL;
137137

138138
va_list ap;
@@ -642,8 +642,7 @@ void dt_control_jobs_init(dt_control_t *control)
642642
dt_pthread_mutex_unlock(&control->run_mutex);
643643
for(int k = 0; k < control->num_threads; k++)
644644
{
645-
worker_thread_parameters_t *params
646-
= (worker_thread_parameters_t *)calloc(1, sizeof(worker_thread_parameters_t));
645+
worker_thread_parameters_t *params = calloc(1, sizeof(worker_thread_parameters_t));
647646
params->self = control;
648647
params->threadid = k;
649648
dt_pthread_create(&control->thread[k], _control_work, params);
@@ -656,8 +655,7 @@ void dt_control_jobs_init(dt_control_t *control)
656655
{
657656
control->job_res[k] = NULL;
658657
control->new_res[k] = 0;
659-
worker_thread_parameters_t *params
660-
= (worker_thread_parameters_t *)calloc(1, sizeof(worker_thread_parameters_t));
658+
worker_thread_parameters_t *params = calloc(1, sizeof(worker_thread_parameters_t));
661659
params->self = control;
662660
params->threadid = k;
663661
dt_pthread_create(&control->thread_res[k], _control_work_res, params);

src/control/jobs/film_jobs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dt_job_t *dt_film_import1_create(dt_film_t *film)
6464
{
6565
dt_job_t *job = dt_control_job_create(&dt_film_import1_run, "cache load raw images for preview");
6666
if(!job) return NULL;
67-
dt_film_import1_t *params = (dt_film_import1_t *)calloc(1, sizeof(dt_film_import1_t));
67+
dt_film_import1_t *params = calloc(1, sizeof(dt_film_import1_t));
6868
if(!params)
6969
{
7070
dt_control_job_dispose(job);
@@ -101,7 +101,7 @@ dt_job_t *dt_pathlist_import_create(int argc, char *argv[])
101101
{
102102
dt_job_t *job = dt_control_job_create(&_pathlist_import_run, "import commandline images");
103103
if(!job) return NULL;
104-
dt_film_import1_t *params = (dt_film_import1_t *)calloc(1, sizeof(dt_film_import1_t));
104+
dt_film_import1_t *params = calloc(1, sizeof(dt_film_import1_t));
105105
if(!params)
106106
{
107107
dt_control_job_dispose(job);

src/control/jobs/image_jobs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dt_job_t *dt_image_load_job_create(int32_t id, dt_mipmap_size_t mip)
5050
{
5151
dt_job_t *job = dt_control_job_create(&dt_image_load_job_run, "load image %d mip %d", id, mip);
5252
if(!job) return NULL;
53-
dt_image_load_t *params = (dt_image_load_t *)calloc(1, sizeof(dt_image_load_t));
53+
dt_image_load_t *params = calloc(1, sizeof(dt_image_load_t));
5454
if(!params)
5555
{
5656
dt_control_job_dispose(job);
@@ -101,7 +101,7 @@ dt_job_t *dt_image_import_job_create(uint32_t filmid, const char *filename)
101101
dt_image_import_t *params;
102102
dt_job_t *job = dt_control_job_create(&dt_image_import_job_run, "import image");
103103
if(!job) return NULL;
104-
params = (dt_image_import_t *)calloc(1, sizeof(dt_image_import_t));
104+
params = calloc(1, sizeof(dt_image_import_t));
105105
if(!params)
106106
{
107107
dt_control_job_dispose(job);

src/control/progress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ dt_progress_t *dt_control_progress_create(dt_control_t *control, gboolean has_pr
299299
const gchar *message)
300300
{
301301
// create the object
302-
dt_progress_t *progress = (dt_progress_t *)calloc(1, sizeof(dt_progress_t));
302+
dt_progress_t *progress = calloc(1, sizeof(dt_progress_t));
303303
dt_pthread_mutex_init(&(progress->mutex), NULL);
304304

305305
// fill it with values

0 commit comments

Comments
 (0)