open_logbuffer: avoid overflow by comparing (long long) (#5113)

I tested this on a machine with 256 GB of RAM.

fixes #4906
This commit is contained in:
Michael Stapelberg 2022-09-09 10:26:17 +02:00 committed by GitHub
parent ac368e7916
commit 4b5ead023e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,7 +137,11 @@ void open_logbuffer(void) {
* For 512 MiB of RAM this will lead to a 5 MiB log buffer.
* At the moment (2011-12-10), no testcase leads to an i3 log
* of more than ~ 600 KiB. */
logbuffer_size = min(physical_mem_bytes * 0.01, shmlog_size);
logbuffer_size = shmlog_size;
if (physical_mem_bytes * 0.01 < (long long)shmlog_size) {
logbuffer_size = physical_mem_bytes * 0.01;
}
#if defined(__FreeBSD__)
sasprintf(&shmlogname, "/tmp/i3-log-%d", getpid());
#else