Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit b0fa283

Browse files
committed
Revise for explicit conversions
1 parent 2f60438 commit b0fa283

20 files changed

Lines changed: 186 additions & 160 deletions

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ AC_ARG_WITH([developer-flags],
603603
[DEVELOPER_FLAGS=no])
604604

605605
AS_IF([test "${DEVELOPER_FLAGS}" = "yes"], [
606-
TEMP_CPPFLAGS="$TEMP_CPPFLAGS -W -Wall -Wextra -Wformat -Wshadow -Wpointer-arith -Wwrite-strings -Winline -Wredundant-decls -Wno-long-long -ggdb -g3"
606+
TEMP_CPPFLAGS="$TEMP_CPPFLAGS -W -Wall -Wextra -Wconversion -Wformat -Wshadow -Wpointer-arith -Wwrite-strings -Winline -Wredundant-decls -Wno-long-long -ggdb -g3"
607607
]
608608
)
609609

src/alg.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define SMARTMASK_SENSITIVITY_INCR 5
3636

3737
typedef struct {
38-
short y, xl, xr, dy;
38+
int y, xl, xr, dy;
3939
} Segment;
4040

4141

@@ -519,7 +519,7 @@ static void alg_despeckle(ctx_dev *cam)
519519
width = cam->imgs.width;
520520
height = cam->imgs.height;
521521
done = 0;
522-
len = cam->conf->despeckle_filter.length();
522+
len = (int)cam->conf->despeckle_filter.length();
523523
common_buffer = cam->imgs.common_buffer;
524524
cam->current_image->total_labels = 0;
525525
cam->imgs.largest_label = 0;
@@ -573,7 +573,8 @@ static void alg_despeckle(ctx_dev *cam)
573573

574574
void alg_tune_smartmask(ctx_dev *cam)
575575
{
576-
int i, diff;
576+
int i;
577+
unsigned char diff;
577578
int motionsize = cam->imgs.motionsize;
578579
unsigned char *smartmask = cam->imgs.smartmask;
579580
unsigned char *smartmask_final = cam->imgs.smartmask_final;
@@ -592,7 +593,7 @@ void alg_tune_smartmask(ctx_dev *cam)
592593
smartmask[i]--;
593594
}
594595
/* Increase smart_mask sensitivity based on the buffered values. */
595-
diff = smartmask_buffer[i] / sensitivity;
596+
diff = (unsigned char)(smartmask_buffer[i] / sensitivity);
596597

597598
if (diff) {
598599
if (smartmask[i] <= diff + 80) {
@@ -610,9 +611,9 @@ void alg_tune_smartmask(ctx_dev *cam)
610611
}
611612
}
612613
/* Further expansion (here:erode due to inverted logic!) of the mask. */
613-
diff = alg_erode9(smartmask_final, cam->imgs.width, cam->imgs.height,
614+
alg_erode9(smartmask_final, cam->imgs.width, cam->imgs.height,
614615
cam->imgs.common_buffer, 255);
615-
diff = alg_erode5(smartmask_final, cam->imgs.width, cam->imgs.height,
616+
alg_erode5(smartmask_final, cam->imgs.width, cam->imgs.height,
616617
cam->imgs.common_buffer, 255);
617618
cam->smartmask_count = cam->smartmask_ratio;
618619
}
@@ -944,7 +945,7 @@ void alg_update_reference_frame(ctx_dev *cam, int action)
944945
(*ref_dyn)++; /* Motionpixel? Keep excluding from ref frame. */
945946
} else {
946947
*ref_dyn = 0; /* Nothing special - release pixel. */
947-
*ref = (*ref + *image_virgin) / 2;
948+
*ref = (unsigned char)((*ref + *image_virgin) / 2);
948949
}
949950

950951
} else { /* No motion: copy to ref frame. */
@@ -1048,7 +1049,7 @@ static void alg_location_dist(ctx_dev *cam)
10481049
if (*(out++)) {
10491050
variance_x += ((x - cent->x) * (x - cent->x));
10501051
variance_y += ((y - cent->y) * (y - cent->y));
1051-
distance_mean += sqrt(
1052+
distance_mean += (uint64_t)sqrt(
10521053
((x - cent->x) * (x - cent->x)) +
10531054
((y - cent->y) * (y - cent->y)));
10541055

@@ -1074,9 +1075,9 @@ static void alg_location_dist(ctx_dev *cam)
10741075
cent->maxx = cent->x + xdist / centc * 3;
10751076
cent->miny = cent->y - ydist / centc * 3;
10761077
cent->maxy = cent->y + ydist / centc * 3;
1077-
cent->stddev_x = sqrt((variance_x / centc));
1078-
cent->stddev_y = sqrt((variance_y / centc));
1079-
distance_mean = (distance_mean / centc);
1078+
cent->stddev_x = (int)sqrt((variance_x / centc));
1079+
cent->stddev_y = (int)sqrt((variance_y / centc));
1080+
distance_mean = (uint64_t)(distance_mean / centc);
10801081
} else {
10811082
cent->stddev_y = 0;
10821083
cent->stddev_x = 0;
@@ -1089,16 +1090,16 @@ static void alg_location_dist(ctx_dev *cam)
10891090
for (x = 0; x < width; x++) {
10901091
if (*(out++)) {
10911092
variance_xy += (
1092-
(sqrt(((x - cent->x) * (x - cent->x)) +
1093+
((uint64_t)sqrt(((x - cent->x) * (x - cent->x)) +
10931094
((y - cent->y) * (y - cent->y))) - distance_mean) *
1094-
(sqrt(((x - cent->x) * (x - cent->x)) +
1095+
((uint64_t)sqrt(((x - cent->x) * (x - cent->x)) +
10951096
((y - cent->y) * (y - cent->y))) - distance_mean));
10961097
}
10971098
}
10981099
}
10991100
/* Per statistics, divide by n-1 for calc of a standard deviation */
11001101
if ((centc-1) > 0) {
1101-
cent->stddev_xy = sqrt((variance_xy / (centc-1)));
1102+
cent->stddev_xy = (int)sqrt((variance_xy / (centc-1)));
11021103
}
11031104
}
11041105

src/alg_sec.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525

2626
#ifdef HAVE_OPENCV
2727

28-
#include <opencv2/objdetect.hpp>
29-
#include <opencv2/dnn.hpp>
30-
#include <opencv2/highgui.hpp>
31-
#include <opencv2/imgproc.hpp>
32-
#include <opencv2/imgcodecs.hpp>
33-
#include <opencv2/videoio.hpp>
34-
#include <opencv2/video.hpp>
28+
#pragma GCC diagnostic push
29+
#pragma GCC diagnostic ignored "-Wconversion"
30+
#include <opencv2/objdetect.hpp>
31+
#include <opencv2/dnn.hpp>
32+
#include <opencv2/highgui.hpp>
33+
#include <opencv2/imgproc.hpp>
34+
#include <opencv2/imgcodecs.hpp>
35+
#include <opencv2/videoio.hpp>
36+
#include <opencv2/video.hpp>
37+
#pragma GCC diagnostic pop
3538

3639
using namespace cv;
3740
using namespace dnn;

src/alg_sec.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323

2424

2525
#ifdef HAVE_OPENCV
26-
#include "opencv2/objdetect.hpp"
27-
#include "opencv2/dnn.hpp"
28-
#include "opencv2/highgui.hpp"
29-
#include "opencv2/imgproc.hpp"
26+
#pragma GCC diagnostic push
27+
#pragma GCC diagnostic ignored "-Wconversion"
28+
#include "opencv2/objdetect.hpp"
29+
#include "opencv2/dnn.hpp"
30+
#include "opencv2/highgui.hpp"
31+
#include "opencv2/imgproc.hpp"
32+
#pragma GCC diagnostic pop
3033
#endif
3134

3235

@@ -42,10 +45,10 @@ struct ctx_algsec_model {
4245
std::string image_type;
4346
int rotate;
4447

45-
float scalefactor;
46-
float threshold; /* Threshold for motion to use on detection*/
48+
double scalefactor;
49+
double threshold; /* Threshold for motion to use on detection*/
4750

48-
float hog_threshold_model; /* Threshold fed into the opencv model*/
51+
double hog_threshold_model; /* Threshold fed into the opencv model*/
4952
int hog_winstride;
5053
int hog_padding;
5154

@@ -63,7 +66,7 @@ struct ctx_algsec_model {
6366
std::vector<std::string> dnn_classes;
6467
int dnn_width;
6568
int dnn_height;
66-
float dnn_scale;
69+
double dnn_scale;
6770

6871
bool isdetected; /* Bool reset for each image as to whether a detection occurred */
6972

src/dbse.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,19 @@ static void dbse_rec_assign(ctx_dbse_rec *rec, char *col_nm, char *col_val)
218218

219219
} else if (mystrceq(col_nm,"movie_nm")) {
220220
free(rec->movie_nm);
221-
flen = strlen(col_val);
221+
flen = (int)strlen(col_val);
222222
rec->movie_nm = (char*)mymalloc(flen + 1);
223223
snprintf(rec->movie_nm, flen+1,"%s",col_val);
224224

225225
} else if (mystrceq(col_nm,"movie_dir")) {
226226
free(rec->movie_dir);
227-
flen = strlen(col_val);
227+
flen = (int)strlen(col_val);
228228
rec->movie_dir = (char*)mymalloc(flen + 1);
229229
snprintf(rec->movie_dir, flen+1,"%s",col_val);
230230

231231
} else if (mystrceq(col_nm,"full_nm")) {
232232
free(rec->full_nm);
233-
flen = strlen(col_val);
233+
flen = (int)strlen(col_val);
234234
rec->full_nm = (char*)mymalloc(flen + 1);
235235
snprintf(rec->full_nm, flen+1,"%s",col_val);
236236
if (stat(rec->full_nm, &statbuf) == 0) {
@@ -245,15 +245,15 @@ static void dbse_rec_assign(ctx_dbse_rec *rec, char *col_nm, char *col_val)
245245

246246
} else if (mystrceq(col_nm,"movie_tmc")) {
247247
free(rec->movie_tmc);
248-
flen = strlen(col_val);
248+
flen = (int)strlen(col_val);
249249
rec->movie_tmc =
250250
(char*)mymalloc(flen + 1);
251251
snprintf(rec->movie_tmc
252252
,flen+1,"%s",col_val);
253253

254254
} else if (mystrceq(col_nm,"movie_tml")) {
255255
free(rec->movie_tml);
256-
flen = strlen(col_val);
256+
flen = (int)strlen(col_val);
257257
rec->movie_tml =
258258
(char*)mymalloc(flen + 1);
259259
snprintf(rec->movie_tml

src/draw.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,14 +1152,14 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start
11521152
txtlen = 0;
11531153
while ((end = strstr(end, NEWLINE))) {
11541154
if ((end - begin)>txtlen) {
1155-
txtlen = (end - begin);
1155+
txtlen = (int)(end - begin);
11561156
}
11571157
num_nl++;
11581158
end += sizeof(NEWLINE)-1;
11591159
begin = end;
11601160
}
11611161
if (txtlen == 0) {
1162-
txtlen = strlen(text);
1162+
txtlen = (int)strlen(text);
11631163
}
11641164

11651165
/* Adjust the factor if it is out of bounds
@@ -1186,15 +1186,15 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start
11861186
begin = end = text;
11871187

11881188
while ((end = strstr(end, NEWLINE))) {
1189-
int len = end-begin;
1189+
int len = (int)(end-begin);
11901190

11911191
draw_textn(image, startx, starty, width, begin, len, factor);
11921192
end += sizeof(NEWLINE)-1;
11931193
begin = end;
11941194
starty += line_space;
11951195
}
11961196

1197-
draw_textn(image, startx, starty, width, begin, strlen(begin), factor);
1197+
draw_textn(image, startx, starty, width, begin, (int)strlen(begin), factor);
11981198

11991199
return 0;
12001200
}

src/event.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ static void event_newfile(ctx_dev *cam, motion_event evnt
8181
static void on_picture_save_command(ctx_dev *cam, motion_event evnt
8282
,ctx_image_data *img_data, char *fname, void *ftype, struct timespec *ts1)
8383
{
84-
85-
int filetype = (unsigned long)ftype;
84+
/*Fix me*/
85+
long filetype = (long)ftype;
8686

8787
(void)evnt;
8888
(void)img_data;
8989
(void)ts1;
9090

9191
if ((filetype & FTYPE_IMAGE_ANY) != 0 && (cam->conf->on_picture_save != "")) {
92-
util_exec_command(cam, cam->conf->on_picture_save.c_str(), fname, filetype);
92+
util_exec_command(cam, cam->conf->on_picture_save.c_str(), fname, (int)filetype);
9393
}
9494

9595
if ((filetype & FTYPE_MOVIE_ANY) != 0 && (cam->conf->on_movie_start != "")) {
96-
util_exec_command(cam, cam->conf->on_movie_start.c_str(), fname, filetype);
96+
util_exec_command(cam, cam->conf->on_movie_start.c_str(), fname, (int)filetype);
9797
}
9898
}
9999

@@ -280,7 +280,7 @@ static void event_image_snapshot(ctx_dev *cam, motion_event evnt
280280
(void)fname;
281281
(void)ftype;
282282

283-
offset = cam->conf->snapshot_filename.length() - 8;
283+
offset = (int)cam->conf->snapshot_filename.length() - 8;
284284
if (offset < 0) {
285285
offset = 1;
286286
}
@@ -422,14 +422,14 @@ static void on_movie_end_command(ctx_dev *cam, motion_event evnt
422422
,ctx_image_data *img_data, char *fname, void *ftype, struct timespec *ts1)
423423
{
424424

425-
int filetype = (unsigned long) ftype;
425+
long filetype = (long) ftype;
426426

427427
(void)evnt;
428428
(void)img_data;
429429
(void)ts1;
430430

431431
if ((filetype & FTYPE_MOVIE_ANY) && (cam->conf->on_movie_end != "")) {
432-
util_exec_command(cam, cam->conf->on_movie_end.c_str(), fname, filetype);
432+
util_exec_command(cam, cam->conf->on_movie_end.c_str(), fname, (int)filetype);
433433
}
434434
}
435435

src/exif.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,22 @@ static unsigned const char exif_tzoffset_tag[12] = {
8787

8888
static void put_uint16(JOCTET *buf, unsigned value)
8989
{
90-
buf[0] = ( value & 0xFF00 ) >> 8;
91-
buf[1] = ( value & 0x00FF );
90+
buf[0] = (unsigned char)(( value & 0xFF00 ) >> 8);
91+
buf[1] = (unsigned char)(( value & 0x00FF ));
9292
}
9393

9494
static void put_sint16(JOCTET *buf, int value)
9595
{
96-
buf[0] = ( value & 0xFF00 ) >> 8;
97-
buf[1] = ( value & 0x00FF );
96+
buf[0] = (unsigned char)(( value & 0xFF00 ) >> 8);
97+
buf[1] = (unsigned char)(( value & 0x00FF ));
9898
}
9999

100100
static void put_uint32(JOCTET *buf, unsigned value)
101101
{
102-
buf[0] = ( value & 0xFF000000 ) >> 24;
103-
buf[1] = ( value & 0x00FF0000 ) >> 16;
104-
buf[2] = ( value & 0x0000FF00 ) >> 8;
105-
buf[3] = ( value & 0x000000FF );
102+
buf[0] = (unsigned char)(( value & 0xFF000000 ) >> 24);
103+
buf[1] = (unsigned char)(( value & 0x00FF0000 ) >> 16);
104+
buf[2] = (unsigned char)(( value & 0x0000FF00 ) >> 8);
105+
buf[3] = (unsigned char)(( value & 0x000000FF ));
106106
}
107107

108108
struct tiff_writing {
@@ -134,7 +134,7 @@ static void put_direntry(struct tiff_writing *into, const char *data, unsigned l
134134

135135
static void put_stringentry(struct tiff_writing *into, unsigned tag, const char *str, int with_nul)
136136
{
137-
unsigned stringlength = strlen(str) + (with_nul?1:0);
137+
unsigned stringlength = (int)strlen(str) + (with_nul?1:0);
138138

139139
put_uint16(into->buf, tag);
140140
put_uint16(into->buf + 2, TIFF_TYPE_ASCII);
@@ -221,7 +221,7 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam,
221221

222222
if (description) {
223223
ifd0_tagcount ++;
224-
datasize += 5 + strlen(description); /* Add 5 for NUL and alignment */
224+
datasize += 5 + (int)strlen(description); /* Add 5 for NUL and alignment */
225225
}
226226

227227
if (datetime) {
@@ -236,12 +236,12 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam,
236236
ifd0_tagcount++;
237237
/* It would be nice to use the same offset for both tags' values,
238238
* but I don't want to write the bookkeeping for that right now */
239-
datasize += 2 * (5 + strlen(datetime));
239+
datasize += 2 * (5 + (int)strlen(datetime));
240240
}
241241

242242
if (subtime) {
243243
ifd1_tagcount++;
244-
datasize += 5 + strlen(subtime);
244+
datasize += 5 + (int)strlen(subtime);
245245
}
246246

247247
if (box) {
@@ -305,7 +305,7 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam,
305305

306306
if (datetime) {
307307
memcpy(writing.buf, exif_tzoffset_tag, 12);
308-
put_sint16(writing.buf+8, timestamp_tm.tm_gmtoff / 3600);
308+
put_sint16(writing.buf+8, int(timestamp_tm.tm_gmtoff / 3600));
309309
writing.buf += 12;
310310
}
311311

src/jpegutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static GLOBAL(void) _jpeg_mem_dest(j_compress_ptr cinfo, JOCTET* buf, size_t buf
386386
static GLOBAL(int) _jpeg_mem_size(j_compress_ptr cinfo)
387387
{
388388
mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;
389-
return dest->jpegsize;
389+
return (int)dest->jpegsize;
390390
}
391391

392392
/*

0 commit comments

Comments
 (0)