summaryrefslogtreecommitdiff
path: root/src/pulse/volume.c
diff options
context:
space:
mode:
authorGeorg Chini <georg@chini.tk>2017-04-29 10:38:05 +0200
committerGeorg Chini <georg@chini.tk>2017-04-29 10:38:05 +0200
commit68203100ff1d5ac35ade6db4fc56e355274d6a0e (patch)
tree6540c889b9581c73ecd48e1eb8f86b489c4fafc9 /src/pulse/volume.c
parentbe1276d816171d9ce6c981581c22a297a61d62bc (diff)
downloadpulseaudio-68203100ff1d5ac35ade6db4fc56e355274d6a0e.tar.gz
volume: Fix overflow in percent calculation of pa_*volume_snprint*()
The percent calculation could overflow in the pa_*volume_snprint*() functions. For large volumes, volume * 100 can exceed UINT32_MAX. This patch adds appropriate type casts.
Diffstat (limited to 'src/pulse/volume.c')
-rw-r--r--src/pulse/volume.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index 1488028ba..ffd42ecb3 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -313,7 +313,7 @@ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c) {
l -= pa_snprintf(e, l, "%s%u: %3u%%",
first ? "" : " ",
channel,
- (c->values[channel]*100+PA_VOLUME_NORM/2)/PA_VOLUME_NORM);
+ (unsigned)(((uint64_t)c->values[channel] * 100 + (uint64_t)PA_VOLUME_NORM / 2) / (uint64_t)PA_VOLUME_NORM));
e = strchr(e, 0);
first = false;
@@ -333,7 +333,7 @@ char *pa_volume_snprint(char *s, size_t l, pa_volume_t v) {
return s;
}
- pa_snprintf(s, l, "%3u%%", (v*100+PA_VOLUME_NORM/2)/PA_VOLUME_NORM);
+ pa_snprintf(s, l, "%3u%%", (unsigned)(((uint64_t)v * 100 + (uint64_t)PA_VOLUME_NORM / 2) / (uint64_t)PA_VOLUME_NORM));
return s;
}
@@ -446,7 +446,7 @@ char *pa_volume_snprint_verbose(char *s, size_t l, pa_volume_t v, int print_dB)
pa_snprintf(s, l, "%" PRIu32 " / %3u%%%s%s",
v,
- (v * 100 + PA_VOLUME_NORM / 2) / PA_VOLUME_NORM,
+ (unsigned)(((uint64_t)v * 100 + (uint64_t)PA_VOLUME_NORM / 2) / (uint64_t)PA_VOLUME_NORM),
print_dB ? " / " : "",
print_dB ? pa_sw_volume_snprint_dB(dB, sizeof(dB), v) : "");