linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Linphone-developers] Patches for GCC 8.1 build failures


From: Jan Kundrát
Subject: [Linphone-developers] Patches for GCC 8.1 build failures
Date: Fri, 09 Nov 2018 19:55:04 +0100
User-agent: Trojita/v0.7-361-gfee56b6f-dirty; Qt/5.11.0; xcb; Linux; Gentoo Base System release 2.4.1

Hi,
GCC 7.x introduced additional build-time checks for functions such as sprintf. The compiler now warns if it sees a possibility of a buffer overflow or truncation. I'm building linphone on a desktop Linux with GCC 8.1, and because the build (of at least some packages) enforces -Werror, I was getting build failures.

(Please consider removing -Werror, it breaks the build for your future users.)

Switching to snprintf() did not help; apparently the compiler still considers truncation as an error.

It was necessary to use modulo arithmetics so that the compiler can infer that it's just, e.g., four digits per year. After that the numbers still wouldn't fit because the compiler wasn't sure that they are positive -- hence the static_cast<unsigned>.

In vo-amrwbenc I simply removed the __unused stanza. It looks like a non-standard way of silencing a warning about an unused variable. I don't know C and I do not know which C standard you're targetting (and the situation with __attribute__(unused) is not standard AFAIU), so I simply removed that declaration -- the build succeeded after that.

Can you please ensure that these patches eventually reach the respective projects' upstreams? I see that you're distributing a fork which is based on an older version, at least with SOCI.

Thanks for your SW, btw.

Cheers,
Jan
From c50a3c0895b028a38d0e0c9682cadda73caf398c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= <address@hidden>
Date: Fri, 9 Nov 2018 12:08:06 +0100
Subject: [PATCH] Fix build failures on GCC 8.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Due to -Werror and -Wformat-truncation, the code screams out loudly when
the compiler cannot infer that the numbers are small enough to fit into
the resulting buffer. This ugliness ensures that the number of digits is
small enough (that's the % modulos), and that there are no negative
numbers (for the minus sign). A simple std::abs is not enough here...

Signed-off-by: Jan Kundrát <address@hidden>
---
 src/core/soci-simple.cpp | 16 ++++++++++++----
 src/core/use-type.cpp    | 10 +++++++---
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/core/soci-simple.cpp b/src/core/soci-simple.cpp
index 7960b0ef..d5988dff 100644
--- a/src/core/soci-simple.cpp
+++ b/src/core/soci-simple.cpp
@@ -683,8 +683,12 @@ void resize_in_map(std::map<std::string, std::vector<T> > 
& m, int new_size)
 char const * format_date(statement_wrapper & wrapper, std::tm const & d)
 {
     std::sprintf(wrapper.date_formatted, "%d %d %d %d %d %d",
-        d.tm_year + 1900, d.tm_mon + 1, d.tm_mday,
-        d.tm_hour, d.tm_min, d.tm_sec);
+        static_cast<unsigned>(d.tm_year + 1900) % 10000,
+        static_cast<unsigned>(d.tm_mon + 1) % 100,
+        static_cast<unsigned>(d.tm_mday) % 100,
+        static_cast<unsigned>(d.tm_hour) % 100,
+        static_cast<unsigned>(d.tm_min) % 100,
+        static_cast<unsigned>(d.tm_sec) % 100);
 
     return wrapper.date_formatted;
 }
@@ -1794,8 +1798,12 @@ SOCI_DECL char const * 
soci_get_use_date(statement_handle st, char const * name)
     // format is: "YYYY MM DD hh mm ss"
     std::tm const & d = wrapper->use_dates[name];
     std::sprintf(wrapper->date_formatted, "%d %d %d %d %d %d",
-        d.tm_year + 1900, d.tm_mon + 1, d.tm_mday,
-        d.tm_hour, d.tm_min, d.tm_sec);
+        static_cast<unsigned>(d.tm_year + 1900) % 10000,
+        static_cast<unsigned>(d.tm_mon + 1) % 100,
+        static_cast<unsigned>(d.tm_mday) % 100,
+        static_cast<unsigned>(d.tm_hour) % 100,
+        static_cast<unsigned>(d.tm_min) % 100,
+        static_cast<unsigned>(d.tm_sec) % 100);
 
     return wrapper->date_formatted;
 }
diff --git a/src/core/use-type.cpp b/src/core/use-type.cpp
index 646a9e7d..15454083 100644
--- a/src/core/use-type.cpp
+++ b/src/core/use-type.cpp
@@ -81,10 +81,14 @@ void standard_use_type::dump_value(std::ostream& os) const
             {
                 std::tm const& t = exchange_type_cast<x_stdtm>(data_);
 
-                char buf[32];
+                char buf[20];
                 snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d",
-                              t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
-                              t.tm_hour, t.tm_min, t.tm_sec);
+                              static_cast<unsigned>(t.tm_year + 1900) % 10000,
+                              static_cast<unsigned>(t.tm_mon + 1) % 100,
+                              static_cast<unsigned>(t.tm_mday) % 100,
+                              static_cast<unsigned>(t.tm_hour) % 100,
+                              static_cast<unsigned>(t.tm_min) % 100,
+                              static_cast<unsigned>(t.tm_sec) % 100);
 
                 os << buf;
             }
-- 
2.19.1

From 1f9a8575ba3ddc39cea3947e264c32bb8d911c1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= <address@hidden>
Date: Fri, 9 Nov 2018 12:19:46 +0100
Subject: [PATCH] Fix build on GCC 8.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Jan Kundrát <address@hidden>
---
 amrwbenc/src/q_pulse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/amrwbenc/src/q_pulse.c b/amrwbenc/src/q_pulse.c
index d658602..80a0b73 100644
--- a/amrwbenc/src/q_pulse.c
+++ b/amrwbenc/src/q_pulse.c
@@ -188,7 +188,7 @@ Word32 quant_4p_4N(                        /* (o) return 
4*N bits             */
                Word16 pos[],                         /* (i) position of the 
pulse 1..4  */
                Word16 N)                             /* (i) number of bits for 
position */
 {
-       Word16 nb_pos, mask __unused, n_1, tmp;
+       Word16 nb_pos, mask, n_1, tmp;
        Word16 posA[4], posB[4];
        Word32 i, j, k, index;
 
-- 
2.19.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]