mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
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.
This commit is contained in:
parent
be1276d816
commit
68203100ff
1 changed files with 3 additions and 3 deletions
|
|
@ -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) : "");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue