text autosize could overflow

This commit is contained in:
John Cupitt 2017-09-21 10:39:37 +01:00
parent 64be1d89b5
commit 809f523274
1 changed files with 10 additions and 6 deletions

View File

@ -48,8 +48,8 @@
*/
/*
#define DEBUG
*/
#define DEBUG
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -290,14 +290,18 @@ vips_text_autofit( VipsText *text, VipsRect *out_extents )
}
}
if( difference > 0 ) {
text->dpi = lower_dpi;
*out_extents = lower_extents;
}
else {
/* If we've hit the target exactly and quit the loop, diff will be 0
* and we can use upper. Otherwise we are straddling the target and we
* must take lower.
*/
if( difference == 0 ) {
text->dpi = upper_dpi;
*out_extents = upper_extents;
}
else {
text->dpi = lower_dpi;
*out_extents = lower_extents;
}
return( 0 );
}