[vlc-commits] [Git][videolan/vlc][master] 4 commits: modules: optimize empty string check

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Sep 8 05:59:31 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
159906a5 by Steve Lhomme at 2022-09-08T05:38:38+00:00
modules: optimize empty string check

- - - - -
fc6ade22 by Steve Lhomme at 2022-09-08T05:38:38+00:00
modules: optimize string minimum size checks

No need to go through all the chars when we can just check a minimum size with
strnlen().

- - - - -
a82ecdfa by Steve Lhomme at 2022-09-08T05:38:38+00:00
decklink: simplify the mode string usage

The mode can never be NULL. If it was, autodetect is set to false so we never
reach this code.

We can optimize the strlen() calls with a single strnlen() call that will only
test up to 5 chars to check we don't have 3 or 4 chars.

- - - - -
317f1f95 by Steve Lhomme at 2022-09-08T05:38:38+00:00
modules: optimize string maximum size checks

No need to go through all the chars when we can test the the maximum size we
want to reach before deciding it's too much with strnlen().

- - - - -


12 changed files:

- modules/access/decklink.cpp
- modules/access/dsm/access.c
- modules/codec/atsc_a65.c
- modules/codec/libass.c
- modules/codec/webvtt/subsvtt.c
- modules/demux/mjpeg.c
- modules/demux/mkv/mkv.cpp
- modules/gui/macosx/coreinteraction/VLCVideoFilterHelper.m
- modules/misc/audioscrobbler.c
- modules/stream_filter/hds/hds.c
- modules/stream_out/rtp.c
- modules/stream_out/rtsp.c


Changes:

=====================================
modules/access/decklink.cpp
=====================================
@@ -648,8 +648,9 @@ static int Open(vlc_object_t *p_this)
         /* Enable a random format, we will reconfigure on format detection */
         u.id = bmdModeHD1080p2997;
     } else {
-        if (!mode || strlen(mode) < 3 || strlen(mode) > 4) {
-            msg_Err(demux, "Invalid mode: \'%s\'", mode ? mode : "");
+        size_t min_size = strnlen(mode, 4+1);
+        if (min_size < 3 || min_size > 4) {
+            msg_Err(demux, "Invalid mode: \'%s\'", mode);
             free(mode);
             goto finish;
         }


=====================================
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/ */


=====================================
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;


=====================================
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;
 


=====================================
modules/codec/webvtt/subsvtt.c
=====================================
@@ -734,7 +734,7 @@ static bool webvtt_domnode_Match_Attribute( const webvtt_dom_node_t *p_node,
                 psz_start = p_tagnode->psz_attrs;
 
             if( !p_matchsel ) /* attribute check only */
-                return strlen( psz_start ) > 0;
+                return *psz_start != '\0';
 
             return MatchAttribute( psz_start, p_matchsel->psz_name, p_matchsel->match );
         }


=====================================
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))))


=====================================
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;
 


=====================================
modules/gui/macosx/coreinteraction/VLCVideoFilterHelper.m
=====================================
@@ -99,7 +99,7 @@
             }
 
             /* Remove trailing : : */
-            if (strlen(psz_string) > 0 && *(psz_string + strlen(psz_string) -1) == ':')
+            if (*psz_string != '\0' && *(psz_string + strlen(psz_string) -1) == ':')
                 *(psz_string + strlen(psz_string) -1) = '\0';
         } else {
             free(psz_string);


=====================================
modules/misc/audioscrobbler.c
=====================================
@@ -590,7 +590,7 @@ static int Handshake(intf_thread_t *p_this)
         goto proto;
 
     p_buffer_pos = strstr(p_buffer_pos, "\n");
-    if (!p_buffer_pos || strlen(p_buffer_pos) < 33)
+    if (!p_buffer_pos || strnlen(p_buffer_pos, 33) < 33)
         goto proto;
     p_buffer_pos++; /* we skip the '\n' */
 


=====================================
modules/stream_filter/hds/hds.c
=====================================
@@ -761,7 +761,7 @@ static uint8_t* download_chunk( stream_t *s,
     const char* quality = "";
     char* server_base = sys->base_url;
     if( stream->server_entry_count > 0 &&
-        strlen(stream->server_entries[0]) > 0 )
+        stream->server_entries[0][0] != '\0' )
     {
         server_base = stream->server_entries[0];
     }


=====================================
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 */


=====================================
modules/stream_out/rtsp.c
=====================================
@@ -196,7 +196,7 @@ static void RtspTrackClose( rtsp_strack_t *tr );
 
 char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base )
 {
-    const char *sep = strlen( base ) > 0 && base[strlen( base ) - 1] == '/' ?
+    const char *sep = *base != '\0' && base[strlen( base ) - 1] == '/' ?
                       "" : "/";
     char *url;
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2f4ba073a396d1bacf0402790d0002c2a3d534f6...317f1f95694cc29b3615a80f016a4b6f29e46ec3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2f4ba073a396d1bacf0402790d0002c2a3d534f6...317f1f95694cc29b3615a80f016a4b6f29e46ec3
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list