From 4171f2673da8ddd743ed867abfbafc77c1502f23 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 17 Jul 2012 10:10:34 +0100 Subject: [PATCH] safer string equality in cache it could segv if operations had strings which had been set to NULL --- libvips/iofuncs/cache.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libvips/iofuncs/cache.c b/libvips/iofuncs/cache.c index d15e8bb5..81fc6d26 100644 --- a/libvips/iofuncs/cache.c +++ b/libvips/iofuncs/cache.c @@ -265,9 +265,15 @@ vips_value_equal( GParamSpec *pspec, GValue *v1, GValue *v2 ) if( generic == G_TYPE_PARAM_DOUBLE ) return( g_value_get_double( v1 ) == g_value_get_double( v2 ) ); - if( generic == G_TYPE_PARAM_STRING ) - return( strcmp( g_value_get_string( v1 ), - g_value_get_string( v2 ) ) == 0 ); + if( generic == G_TYPE_PARAM_STRING ) { + const char *s1 = g_value_get_string( v1 ); + const char *s2 = g_value_get_string( v2 ); + + if( s1 == s2 ) + return( TRUE ); + else + return( s1 && s2 && strcmp( s1, s2 ) == 0 ); + } if( generic == G_TYPE_PARAM_BOXED ) return( g_value_get_boxed( v1 ) == g_value_get_boxed( v2 ) );