summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2019-07-12 18:01:47 +0200
committerDan Fandrich <dan@coneharvesters.com>2019-07-12 18:01:47 +0200
commit8197bf4a655197c49c0f57ace91d87c4be810e6a (patch)
treee66dbdc5357725f1497a1a75c76eceeb04cf251e
parent37a9fd9b5dd0fa3225a22b864dc50e5ea01565d8 (diff)
downloadlibexif-8197bf4a655197c49c0f57ace91d87c4be810e6a.tar.gz
libexif-8197bf4a655197c49c0f57ace91d87c4be810e6a.tar.bz2
libexif-8197bf4a655197c49c0f57ace91d87c4be810e6a.zip
Stopped printing some values as int in exif_entry_get_value
By leaving them as double, it avoids undefined behaviour when the values are out of the range of an int. This also has the side effect of rounding some values to the nearest integer, improving display accuracy. Patch from Google.
-rw-r--r--libexif/exif-entry.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libexif/exif-entry.c b/libexif/exif-entry.c
index c2980ea..34159c1 100644
--- a/libexif/exif-entry.c
+++ b/libexif/exif-entry.c
@@ -1053,9 +1053,9 @@ exif_entry_get_value (ExifEntry *e, char *val, unsigned int maxlen)
}
}
if (d)
- snprintf (b, sizeof (b), _(" (35 equivalent: %d mm)"),
- (int) (d * (double) v_rat.numerator /
- (double) v_rat.denominator));
+ snprintf (b, sizeof (b), _(" (35 equivalent: %.0f mm)"),
+ (d * (double) v_rat.numerator /
+ (double) v_rat.denominator));
else
b[0] = 0;
@@ -1084,9 +1084,9 @@ exif_entry_get_value (ExifEntry *e, char *val, unsigned int maxlen)
}
d = (double) v_rat.numerator / (double) v_rat.denominator;
if (d < 1)
- snprintf (val, maxlen, _("1/%i"), (int) (0.5 + 1. / d));
+ snprintf (val, maxlen, _("1/%.0f"), 1. / d);
else
- snprintf (val, maxlen, "%i", (int) d);
+ snprintf (val, maxlen, "%.0f", d);
strncat (val, _(" sec."), maxlen-1 - strlen (val));
break;
case EXIF_TAG_SHUTTER_SPEED_VALUE:
@@ -1101,9 +1101,9 @@ exif_entry_get_value (ExifEntry *e, char *val, unsigned int maxlen)
snprintf (val, maxlen, _("%.02f EV"), d);
d = 1. / pow (2, d);
if (d < 1)
- snprintf (b, sizeof (b), _(" (1/%d sec.)"), (int) (1. / d));
+ snprintf (b, sizeof (b), _(" (1/%.0f sec.)"), 1. / d);
else
- snprintf (b, sizeof (b), _(" (%d sec.)"), (int) d);
+ snprintf (b, sizeof (b), _(" (%.0f sec.)"), d);
strncat (val, b, maxlen-1 - strlen (val));
break;
case EXIF_TAG_BRIGHTNESS_VALUE: