[vlc-commits] archive: avoid duplicate strchr() call

Rémi Denis-Courmont git at videolan.org
Sat Nov 15 12:01:04 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 15 13:00:43 2014 +0200| [ecae18a3d2e364d077df60f9956ad458895d374c] | committer: Rémi Denis-Courmont

archive: avoid duplicate strchr() call

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ecae18a3d2e364d077df60f9956ad458895d374c
---

 modules/access/archive/access.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/modules/access/archive/access.c b/modules/access/archive/access.c
index 6a4fca4..3ba99cf 100644
--- a/modules/access/archive/access.c
+++ b/modules/access/archive/access.c
@@ -308,15 +308,16 @@ static int Control(access_t *p_access, int i_query, va_list args)
 int AccessOpen(vlc_object_t *p_object)
 {
     access_t *p_access = (access_t*)p_object;
-
-    if (!strchr(p_access->psz_location, ARCHIVE_SEP_CHAR))
+    const char *sep = strchr(p_access->psz_location, ARCHIVE_SEP_CHAR);
+    if (sep == NULL)
         return VLC_EGENERIC;
 
     char *psz_base = strdup(p_access->psz_location);
-    if (!psz_base)
-        return VLC_EGENERIC;
-    char *psz_name = strchr(psz_base, ARCHIVE_SEP_CHAR);
-    *psz_name++ = '\0';
+    if (unlikely(psz_base == NULL))
+        return VLC_EENOMEM;
+
+    const char *psz_name = psz_base + (sep - p_access->psz_location);
+    *(psz_name++) = '\0';
 
     if (decode_URI(psz_base) == NULL)
     {



More information about the vlc-commits mailing list