From 45dbf9096d8ba74856b31136a8842adaeeb85b40 Mon Sep 17 00:00:00 2001 From: Antoine B Date: Wed, 10 Jul 2024 06:10:23 +0200 Subject: [PATCH] Fixed potentially uninitialized variable (#41) In the case where the file has reached the end, readBin doesn't initialize the "bytes" variable. It therefore contains garbage values, which has a small chance of making the switch select another case than "default", leading to an infinite loop. This isn't just speculation, this has actually happened to me while compiling in Unreal 5.3. It is worth mentionning that the idiomatic way of checking whether or not the file has reached the end is to use file.eof() instead of relying on the fact that the variable isn't touched by "read". --- xdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xdf.cpp b/xdf.cpp index 5260bb9..67f86fc 100644 --- a/xdf.cpp +++ b/xdf.cpp @@ -712,7 +712,7 @@ void Xdf::resample(int userSrate) //function of reading the length of each chunk uint64_t Xdf::readLength(std::ifstream &file) { - uint8_t bytes; + uint8_t bytes = 0; Xdf::readBin(file, &bytes); uint64_t length = 0;