From cbfbeb6e2d517cd6bf510a4b89265604bebb2cd0 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 28 Nov 2022 08:51:13 +0000 Subject: [PATCH] don't parse floats with scanf since scanf uses the current locale, duh see https://github.com/libvips/libvips/issues/3191 --- libvips/iofuncs/object.c | 5 +---- libvips/iofuncs/type.c | 14 +++----------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 47bdb3e1..8d099c9f 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -2083,11 +2083,8 @@ vips_object_set_argument_from_string( VipsObject *object, return( -1 ); } - if( sscanf( value, "%lg", &d ) != 1 ) { - vips_error( class->nickname, - _( "'%s' is not a double" ), value ); + if( vips_strtod( value, &d ) ) return( -1 ); - } g_value_init( &gvalue, G_TYPE_DOUBLE ); g_value_set_double( &gvalue, d ); diff --git a/libvips/iofuncs/type.c b/libvips/iofuncs/type.c index affc25de..d3ee657a 100644 --- a/libvips/iofuncs/type.c +++ b/libvips/iofuncs/type.c @@ -931,14 +931,11 @@ transform_g_string_array_int( const GValue *src_value, GValue *dest_value ) /* Walk the string to get the number of elements. * We need a copy of the string, since we insert \0 during * scan. - * - * We can't allow ',' as a separator, since some locales use it as a - * decimal point. */ str = g_value_dup_string( src_value ); n = 0; - for( p = str; (q = vips_break_token( p, "\t; " )); p = q ) + for( p = str; (q = vips_break_token( p, "\t;, " )); p = q ) n += 1; g_free( str ); @@ -1158,14 +1155,11 @@ transform_g_string_array_double( const GValue *src_value, GValue *dest_value ) /* Walk the string to get the number of elements. * We need a copy of the string, since we insert \0 during scan. - * - * We can't allow ',' as a separator since some locales use it as a - * decimal point. */ str = g_value_dup_string( src_value ); n = 0; - for( p = str; (q = vips_break_token( p, "\t; " )); p = q ) + for( p = str; (q = vips_break_token( p, "\t;, " )); p = q ) n += 1; g_free( str ); @@ -1177,11 +1171,9 @@ transform_g_string_array_double( const GValue *src_value, GValue *dest_value ) i = 0; for( p = str; (q = vips_break_token( p, "\t; " )); p = q ) { - if( sscanf( p, "%lf", &array[i] ) != 1 ) { + if( !vips_strtod( p, &array[i] ) ) { /* Set array to length zero to indicate an error. */ - vips_error( "vipstype", - _( "unable to convert \"%s\" to float" ), p ); vips_value_set_array_double( dest_value, NULL, 0 ); g_free( str ); return;