[libdvdcss-devel] libdvdcss: Skip NULL checks at the end of set_cache_directory().

Diego Biurrun git at videolan.org
Tue Nov 4 16:26:03 CET 2014


libdvdcss | branch: master | Diego Biurrun <diego at biurrun.de> | Tue Nov  4 13:21:05 2014 +0100| [28713727f398b3022e7cb1966ca005863a9e3e25] | committer: Diego Biurrun

libdvdcss: Skip NULL checks at the end of set_cache_directory().

The code guarantees that values have been assigned at this point.

> http://git.videolan.org/gitweb.cgi/libdvdcss.git/?a=commit;h=28713727f398b3022e7cb1966ca005863a9e3e25
---

 src/libdvdcss.c |   22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 65a6267..4fd8aae 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -260,22 +260,14 @@ static char *set_cache_directory( dvdcss_t dvdcss )
 #endif /* ! defined(_WIN32_IE) && _WIN32_IE >= 0x500 */
     }
 
-    /* Sanity check psz_cache value. */
-    if( psz_cache != NULL )
+    /* Check that there is enough space for the cache directory path and the
+     * block filename. The +1 are path separators and terminating null byte. */
+    if( strlen( psz_cache ) + 1 + DISC_TITLE_LENGTH + 1 +
+        MANUFACTURING_DATE_LENGTH + 1 + STRING_KEY_SIZE + 1 +
+        CACHE_FILENAME_LENGTH + 1 > PATH_MAX )
     {
-        if( psz_cache[0] == '\0' )
-        {
-            return NULL;
-        }
-        /* Check that there is enough space for the cache directory path and the
-         * block filename. The +1 are path separators and terminating null byte. */
-        else if( strlen( psz_cache ) + 1 + DISC_TITLE_LENGTH + 1 +
-                 MANUFACTURING_DATE_LENGTH + 1 + STRING_KEY_SIZE + 1 +
-                 CACHE_FILENAME_LENGTH + 1 > PATH_MAX )
-        {
-            print_error( dvdcss, "cache directory name is too long" );
-            return NULL;
-        }
+        print_error( dvdcss, "cache directory name is too long" );
+        return NULL;
     }
     return psz_cache;
 }



More information about the libdvdcss-devel mailing list