From 000be92a0b23846b3f0aa87a5d881a792728b464 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Fri, 16 Aug 2024 07:04:21 +0300 Subject: [PATCH] lint fix --- linters/tox.ini | 1 + src/dump/main.c | 4 ++-- src/libs/capture.c | 24 ++++++++++++------------ src/libs/capture.h | 2 +- src/libs/drm/drm.c | 2 +- src/ustreamer/http/path.c | 2 +- src/ustreamer/options.c | 4 ++-- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/linters/tox.ini b/linters/tox.ini index 0cfef641..4416e38a 100644 --- a/linters/tox.ini +++ b/linters/tox.ini @@ -13,6 +13,7 @@ commands = cppcheck \ --std=c17 \ --error-exitcode=1 \ --quiet \ + --check-level=exhaustive \ --enable=warning,portability,performance,style \ --suppress=assignmentInAssert \ --suppress=variableScope \ diff --git a/src/dump/main.c b/src/dump/main.c index 2738b226..f29e01f9 100644 --- a/src/dump/main.c +++ b/src/dump/main.c @@ -111,9 +111,9 @@ int main(int argc, char *argv[]) { US_LOGGING_INIT; US_THREAD_RENAME("main"); - char *sink_name = NULL; + const char *sink_name = NULL; unsigned sink_timeout = 1; - char *output_path = NULL; + const char *output_path = NULL; bool output_json = false; long long count = 0; long double interval = 0; diff --git a/src/libs/capture.c b/src/libs/capture.c index 15a2de4b..ed613ad8 100644 --- a/src/libs/capture.c +++ b/src/libs/capture.c @@ -83,9 +83,9 @@ static const struct { }; static int _capture_wait_buffer(us_capture_s *cap); -static int _capture_consume_event(us_capture_s *cap); +static int _capture_consume_event(const us_capture_s *cap); static void _v4l2_buffer_copy(const struct v4l2_buffer *src, struct v4l2_buffer *dest); -static bool _capture_is_buffer_valid(us_capture_s *cap, const struct v4l2_buffer *buf, const u8 *data); +static bool _capture_is_buffer_valid(const us_capture_s *cap, const struct v4l2_buffer *buf, const u8 *data); static int _capture_open_check_cap(us_capture_s *cap); static int _capture_open_dv_timings(us_capture_s *cap, bool apply); static int _capture_open_format(us_capture_s *cap, bool first); @@ -98,12 +98,12 @@ static int _capture_open_queue_buffers(us_capture_s *cap); static int _capture_open_export_to_dma(us_capture_s *cap); static int _capture_apply_resolution(us_capture_s *cap, uint width, uint height, float hz); -static void _capture_apply_controls(us_capture_s *cap); +static void _capture_apply_controls(const us_capture_s *cap); static int _capture_query_control( - us_capture_s *cap, struct v4l2_queryctrl *query, + const us_capture_s *cap, struct v4l2_queryctrl *query, const char *name, uint cid, bool quiet); static void _capture_set_control( - us_capture_s *cap, const struct v4l2_queryctrl *query, + const us_capture_s *cap, const struct v4l2_queryctrl *query, const char *name, uint cid, int value, bool quiet); static const char *_format_to_string_nullable(uint format); @@ -421,7 +421,7 @@ int us_capture_hwbuf_grab(us_capture_s *cap, us_capture_hwbuf_s **hw) { return buf.index; } -int us_capture_hwbuf_release(us_capture_s *cap, us_capture_hwbuf_s *hw) { +int us_capture_hwbuf_release(const us_capture_s *cap, us_capture_hwbuf_s *hw) { assert(atomic_load(&hw->refs) == 0); const uint index = hw->buf.index; _LOG_DEBUG("Releasing HW buffer=%u ...", index); @@ -486,7 +486,7 @@ int _capture_wait_buffer(us_capture_s *cap) { return 0; } -static int _capture_consume_event(us_capture_s *cap) { +static int _capture_consume_event(const us_capture_s *cap) { struct v4l2_event event; if (us_xioctl(cap->run->fd, VIDIOC_DQEVENT, &event) < 0) { _LOG_PERROR("Can't consume V4L2 event"); @@ -513,7 +513,7 @@ static void _v4l2_buffer_copy(const struct v4l2_buffer *src, struct v4l2_buffer } } -bool _capture_is_buffer_valid(us_capture_s *cap, const struct v4l2_buffer *buf, const u8 *data) { +bool _capture_is_buffer_valid(const us_capture_s *cap, const struct v4l2_buffer *buf, const u8 *data) { // Workaround for broken, corrupted frames: // Under low light conditions corrupted frames may get captured. // The good thing is such frames are quite small compared to the regular frames. @@ -737,7 +737,7 @@ static int _capture_open_format(us_capture_s *cap, bool first) { _format_to_string_supported(cap->format), _format_to_string_supported(FMT(pixelformat))); - char *format_str; + const char *format_str; if ((format_str = (char*)_format_to_string_nullable(FMT(pixelformat))) != NULL) { _LOG_INFO("Falling back to format=%s", format_str); } else { @@ -1037,7 +1037,7 @@ static int _capture_apply_resolution(us_capture_s *cap, uint width, uint height, return 0; } -static void _capture_apply_controls(us_capture_s *cap) { +static void _capture_apply_controls(const us_capture_s *cap) { # define SET_CID_VALUE(x_cid, x_field, x_value, x_quiet) { \ struct v4l2_queryctrl m_query; \ if (_capture_query_control(cap, &m_query, #x_field, x_cid, x_quiet) == 0) { \ @@ -1094,7 +1094,7 @@ static void _capture_apply_controls(us_capture_s *cap) { } static int _capture_query_control( - us_capture_s *cap, struct v4l2_queryctrl *query, + const us_capture_s *cap, struct v4l2_queryctrl *query, const char *name, uint cid, bool quiet) { // cppcheck-suppress redundantPointerOp @@ -1111,7 +1111,7 @@ static int _capture_query_control( } static void _capture_set_control( - us_capture_s *cap, const struct v4l2_queryctrl *query, + const us_capture_s *cap, const struct v4l2_queryctrl *query, const char *name, uint cid, int value, bool quiet) { if (value < query->minimum || value > query->maximum || value % query->step != 0) { diff --git a/src/libs/capture.h b/src/libs/capture.h index 087e16b7..dffe54e1 100644 --- a/src/libs/capture.h +++ b/src/libs/capture.h @@ -133,7 +133,7 @@ int us_capture_open(us_capture_s *cap); void us_capture_close(us_capture_s *cap); int us_capture_hwbuf_grab(us_capture_s *cap, us_capture_hwbuf_s **hw); -int us_capture_hwbuf_release(us_capture_s *cap, us_capture_hwbuf_s *hw); +int us_capture_hwbuf_release(const us_capture_s *cap, us_capture_hwbuf_s *hw); void us_capture_hwbuf_incref(us_capture_hwbuf_s *hw); void us_capture_hwbuf_decref(us_capture_hwbuf_s *hw); diff --git a/src/libs/drm/drm.c b/src/libs/drm/drm.c index 48e2eeb9..036e7764 100644 --- a/src/libs/drm/drm.c +++ b/src/libs/drm/drm.c @@ -614,7 +614,7 @@ static int _drm_find_sink(us_drm_s *drm, uint width, uint height, float hz) { goto done; } - drmModeModeInfo *best; + const drmModeModeInfo *best; if ((best = _find_best_mode(conn, width, height, hz)) == NULL) { _LOG_ERROR("Can't find any appropriate display modes"); drmModeFreeConnector(conn); diff --git a/src/ustreamer/http/path.c b/src/ustreamer/http/path.c index 03e902b8..adf7677d 100644 --- a/src/ustreamer/http/path.c +++ b/src/ustreamer/http/path.c @@ -40,7 +40,7 @@ char *us_simplify_request_path(const char *str) { char pre1; // The one before char pre2; // The one before that char *simplified; - char *start; + const char *start; char *out; char *slash; diff --git a/src/ustreamer/options.c b/src/ustreamer/options.c index 9d8be4ff..66ee853f 100644 --- a/src/ustreamer/options.c +++ b/src/ustreamer/options.c @@ -353,7 +353,7 @@ int options_parse(us_options_s *options, us_capture_s *cap, us_encoder_s *enc, u } # define ADD_SINK(x_prefix) \ - char *x_prefix##_name = NULL; \ + const char *x_prefix##_name = NULL; \ mode_t x_prefix##_mode = 0660; \ bool x_prefix##_rm = false; \ unsigned x_prefix##_client_ttl = 10; \ @@ -364,7 +364,7 @@ int options_parse(us_options_s *options, us_capture_s *cap, us_encoder_s *enc, u # undef ADD_SINK # ifdef WITH_SETPROCTITLE - char *process_name_prefix = NULL; + const char *process_name_prefix = NULL; # endif char short_opts[128];