[vlc-devel] commit: Properly initialize psz_name in PrintObject(). Fixes a warning: " Conditional jump or move depends on uninitialised values" (Jean-Paul Saman )

Jean-Paul Saman jpsaman at videolan.org
Wed Apr 16 19:19:50 CEST 2008


Antoine Cellerier wrote:
> On Wed, Apr 16, 2008, git version control wrote:
>> -    psz_name[0] = '\0';
>> +    memset( &psz_name, 0, sizeof(psz_name) );
> 
> I don't understand why psz_name[0] = '\0' isn't valid. A zero terminated
> string doesn't need to be 0 padded.
> 

Here is the entire context the compiler complaint about.

     psz_name[0] = '\0';
     if( p_this->psz_object_name )
     {
         snprintf( psz_name, 49, " \"%s\"", p_this->psz_object_name );
         if( psz_name[48] )
             psz_name[48] = '\"';
     }

Since psz_name is only null-terminated at position 0 and thus is the 
rest of the array not initialized. In the if statement a decision on the 
contents of psz_name[48]is made, which (if you remember) is not 
initialized. snprintf() copies maximum of 49 characters which is fine, 
but it could also copy less data. Thus psz_name[48] is potentially 
uninitialized.

Gtz
Jean-Paul Saman.



More information about the vlc-devel mailing list