From fc6ade229c103bb695a69d42bae8ddfacb7e05ac Mon Sep 17 00:00:00 2001 From: Steve Lhomme <robux4@ycbcr.xyz> Date: Fri, 2 Sep 2022 06:39:20 +0200 Subject: [PATCH] modules: optimize string minimum size checks No need to go through all the chars when we can just check a minimum size with strnlen(). --- modules/access/dsm/access.c | 2 +- modules/codec/atsc_a65.c | 2 +- modules/codec/libass.c | 2 +- modules/demux/mjpeg.c | 2 +- modules/demux/mkv/mkv.cpp | 2 +- modules/stream_out/rtp.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/access/dsm/access.c b/modules/access/dsm/access.c index 10eabe2ec415..8e2c36a216ea 100644 --- a/modules/access/dsm/access.c +++ b/modules/access/dsm/access.c @@ -645,7 +645,7 @@ static bool get_path( stream_t *p_access ) backslash_path( p_sys->psz_fullpath ); /* Is path longer than just "/" ? */ - if( strlen( p_sys->psz_fullpath ) > 1 ) + if( strnlen( p_sys->psz_fullpath, 1+1 ) > 1 ) { iter = p_sys->psz_fullpath; while( *iter == '\\' ) iter++; /* Handle smb://Host/////Share/ */ diff --git a/modules/codec/atsc_a65.c b/modules/codec/atsc_a65.c index 26cb0ad82576..f6afa978e052 100644 --- a/modules/codec/atsc_a65.c +++ b/modules/codec/atsc_a65.c @@ -72,7 +72,7 @@ atsc_a65_handle_t *atsc_a65_handle_New( const char *psz_lang ) atsc_a65_handle_t *p_handle = malloc( sizeof(*p_handle) ); if( p_handle ) { - if( psz_lang && strlen(psz_lang) > 2 ) + if( psz_lang && strnlen(psz_lang, 2+1) > 2 ) p_handle->psz_lang = strdup( psz_lang ); else p_handle->psz_lang = NULL; diff --git a/modules/codec/libass.c b/modules/codec/libass.c index 475ac7e41c39..c1ba15b3f557 100644 --- a/modules/codec/libass.c +++ b/modules/codec/libass.c @@ -180,7 +180,7 @@ static int Create( vlc_object_t *p_this ) if( !strcasecmp( p_attach->psz_mime, "application/x-truetype-font" ) ) found = true; /* Then extension */ - else if( !found && strlen( p_attach->psz_name ) > 4 ) + else if( !found && strnlen( p_attach->psz_name, 4+1 ) > 4 ) { char *ext = p_attach->psz_name + strlen( p_attach->psz_name ) - 4; diff --git a/modules/demux/mjpeg.c b/modules/demux/mjpeg.c index 7e6aed88bff8..fbe9ddf93ece 100644 --- a/modules/demux/mjpeg.c +++ b/modules/demux/mjpeg.c @@ -507,7 +507,7 @@ static int MimeDemux( demux_t *p_demux ) /* Handle old and new style of separators */ if (!strncmp(p_sys->psz_separator, (char *)(p_sys->p_peek + i + 2), strlen( p_sys->psz_separator )) - || ((strlen(p_sys->psz_separator) > 4) + || ((strnlen(p_sys->psz_separator, 4+1) > 4) && !strncmp(p_sys->psz_separator, "--", 2) && !strncmp(p_sys->psz_separator, (char *)(p_sys->p_peek + i), strlen( p_sys->psz_separator)))) diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp index a1e1b8559a2f..681c45ed6d2e 100644 --- a/modules/demux/mkv/mkv.cpp +++ b/modules/demux/mkv/mkv.cpp @@ -192,7 +192,7 @@ static int OpenInternal( demux_t *p_demux, bool trust_cues ) const char *psz_file; while ((psz_file = vlc_readdir(p_src_dir)) != NULL) { - if (strlen(psz_file) > 4) + if (strnlen(psz_file, 4+1) > 4) { s_filename = s_path + DIR_SEP_CHAR + psz_file; diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c index 7c030da42545..dbb0859c37fa 100644 --- a/modules/stream_out/rtp.c +++ b/modules/stream_out/rtp.c @@ -766,7 +766,7 @@ char *SDPGenerate( sout_stream_t *p_stream, const char *rtsp_url ) inclport = false; /* Check against URL format rtsp://[<ipv6>]:<port>/<path> */ - bool ipv6 = rtsp_url != NULL && strlen( rtsp_url ) > 7 + bool ipv6 = rtsp_url != NULL && strnlen( rtsp_url, 7+1 ) > 7 && rtsp_url[7] == '['; /* Dummy destination address for RTSP */ -- GitLab