Fix an integer overflow warning

Recent GCC versions emit warnings like this during compilation:

<source>:10:31: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow]
   10 |   const uint32_t limits[] = { -minInt, maxInt };
      |                               ^~~~~~~
<source>:10:31: warning: narrowing conversion of '-2147483648' from 'int' to 'uint32_t' {aka 'unsigned int'} [-Wnarrowing]

And clang even treats them like an error.
This commit is contained in:
Timm Bäder 2021-01-04 13:31:11 +01:00
parent f045e3df04
commit e89bf8be7a
2 changed files with 18 additions and 1 deletions

View File

@ -3,7 +3,7 @@
Summary: Library for accessing various audio file formats
Name: audiofile
Version: 0.3.6
Release: 25%{?dist}
Release: 26%{?dist}
Epoch: 1
# library is LGPL / the two programs GPL / see README
License: LGPLv2+ and GPLv2+
@ -28,6 +28,7 @@ Patch5: audiofile-0.3.6-pull44.patch
Patch6: 822b732fd31ffcb78f6920001e9b1fbd815fa712.patch
Patch7: 941774c8c0e79007196d7f1e7afdc97689f869b3.patch
Patch8: fde6d79fb8363c4a329a184ef0b107156602b225.patch
Patch9: integer-overflow.patch
%description
The Audio File library is an implementation of the Audio File Library
@ -57,6 +58,7 @@ other resources you can use to develop Audio File applications.
%patch6 -p1 -b .CVE-2018-17095
%patch7 -p1 -b .CVE-2018-13440
%patch8 -p1 -b .CVE-2018-13440
%patch9 -p1 -b .integer-overflow
%build
@ -95,6 +97,9 @@ make check
%{_mandir}/man3/*
%changelog
* Mon Jan 04 2021 Timm Bäder <tbaeder@redhat.com> - 1:0.3.6-26
- Fix a integer overflow warning with gcc and error with clang
* Mon Jul 27 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1:0.3.6-25
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

12
integer-overflow.patch Normal file
View File

@ -0,0 +1,12 @@
diff -ruN audiofile-0.3.6.orig/test/Sign.cpp audiofile-0.3.6/test/Sign.cpp
--- audiofile-0.3.6.orig/test/Sign.cpp 2021-01-04 12:50:58.563336280 +0100
+++ audiofile-0.3.6/test/Sign.cpp 2021-01-04 13:00:55.536214264 +0100
@@ -157,7 +157,7 @@
AFframecount framesRead = afReadFrames(file, AF_DEFAULT_TRACK, readData, frameCount);
ASSERT_EQ(framesRead, frameCount);
afCloseFile(file);
- const uint32_t expectedData[] = { 0, -kMinInt32, kMaxUInt32 };
+ const uint32_t expectedData[] = { 0, static_cast<uint32_t>(-kMinInt32), kMaxUInt32 };
for (int i=0; i<frameCount; i++)
EXPECT_EQ(readData[i], expectedData[i]);
}