From 206b1a9a5f1b723e7712d3812031aecdb89aed3b Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Wed, 14 Dec 2011 05:40:21 +0000 Subject: [PATCH] (trunk web) fix warnings in tr_urlIsValidTracker() and tr_urlIsValid() found by llvm's scan-build. scan-build found similar warnings in these two functions relating to allowing NULL pointers to be passed as arguments to functions that don't allow NULL. So now those NULL checks are made explicit before the function calls. --- libtransmission/utils.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 13ef6e22f..8e2b7dba4 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -978,11 +978,19 @@ bool tr_urlIsValidTracker( const char * url ) { bool valid; - const int len = url ? strlen(url) : 0; - valid = isValidURLChars( url, len ) - && !tr_urlParse( url, len, NULL, NULL, NULL, NULL ) - && ( !memcmp(url,"http://",7) || !memcmp(url,"https://",8) || !memcmp(url,"udp://",6) ); + if( url == NULL ) + { + valid = false; + } + else + { + const int len = strlen( url ); + + valid = isValidURLChars( url, len ) + && !tr_urlParse( url, len, NULL, NULL, NULL, NULL ) + && ( !memcmp(url,"http://",7) || !memcmp(url,"https://",8) || !memcmp(url,"udp://",6) ); + } return valid; } @@ -992,12 +1000,20 @@ bool tr_urlIsValid( const char * url, int url_len ) { bool valid; - if( ( url_len < 0 ) && ( url != NULL ) ) - url_len = strlen( url ); - valid = isValidURLChars( url, url_len ) - && !tr_urlParse( url, url_len, NULL, NULL, NULL, NULL ) - && ( !memcmp(url,"http://",7) || !memcmp(url,"https://",8) || !memcmp(url,"ftp://",6) || !memcmp(url,"sftp://",7) ); + if( url == NULL ) + { + valid = false; + } + else + { + if( url_len < 0 ) + url_len = strlen( url ); + + valid = isValidURLChars( url, url_len ) + && !tr_urlParse( url, url_len, NULL, NULL, NULL, NULL ) + && ( !memcmp(url,"http://",7) || !memcmp(url,"https://",8) || !memcmp(url,"ftp://",6) || !memcmp(url,"sftp://",7) ); + } return valid; }