code:
Patch taken from the Sage packaging system.

--- lcalc-1.23/include/Lgamma.h	2012-08-08 23:21:55.000000000 +0200
+++ lcalc-1.23/include/Lgamma.h	2014-05-18 21:15:27.786889718 +0200
@@ -77,7 +77,7 @@
 //n=0 should just give log_GAMMA(z)... thus making log_GAMMA
 //code obsolete. But leave log_GAMMA intact anyways.
 template <class ttype>
-precise(ttype) log_GAMMA (ttype z,int n=0)
+precise(ttype) log_GAMMA (ttype z,int n)
 {
     int M;
     precise(ttype) log_G,r,r2,y;
@@ -230,7 +230,7 @@
 //value exp_w which holds exp(-w)
 //computes G(z,w), so there's an extra w^(-z) factor.
 template <class ttype>
-Complex inc_GAMMA (ttype z,ttype w, const char *method="temme", ttype exp_w = 0, bool recycle=false)
+Complex inc_GAMMA (ttype z,ttype w, const char *method, ttype exp_w, bool recycle)
 {

     Complex G;
@@ -334,7 +334,7 @@

 template <class ttype>
-ttype cfrac_GAMMA (ttype z,ttype w, ttype exp_w=0, bool recycle=false)  //computes G(z,w) via continued fraction
+ttype cfrac_GAMMA (ttype z,ttype w, ttype exp_w, bool recycle)  //computes G(z,w) via continued fraction
 {

         ttype G;
@@ -424,7 +424,7 @@
 }

 template <class ttype>
-ttype asympt_GAMMA (ttype z,ttype w, ttype exp_w = 0, bool recycle=false)  //computes G(z,w) via asymptotic series
+ttype asympt_GAMMA (ttype z,ttype w, ttype exp_w, bool recycle)  //computes G(z,w) via asymptotic series
 {

         if(my_verbose>3) cout << "called asympt_GAMMA("<<z<<","<<w<<")"<< endl;
@@ -446,7 +446,7 @@

 template <class ttype>
-ttype comp_inc_GAMMA (ttype z,ttype w,ttype exp_w = 0, bool recycle=false)  //computes g(z,w)
+ttype comp_inc_GAMMA (ttype z,ttype w,ttype exp_w, bool recycle)  //computes g(z,w)
 {

     ttype g;
@@ -604,7 +604,7 @@
 }

 template <class ttype>
-Complex gamma_sum(Complex s, int what_type, ttype *coeff, int N, Double g, Complex l, Double Q, Long Period, Complex delta=1, const char *method="temme")
+Complex gamma_sum(Complex s, int what_type, ttype *coeff, int N, Double g, Complex l, Double Q, Long Period, Complex delta, const char *method)
 {
     Complex SUM=0;


code:
Patch taken from the Sage packaging system.

--- src/include/Lcommon.h	2010-01-31 15:16:45.000000000 +0000
+++ src/include/Lcommon.h	2011-03-08 21:19:11.849443238 +0000
@@ -25,7 +25,7 @@
 #ifdef USE_MPFR
 inline double lcalc_to_double(const double& x) { return x; }
 #endif
-//inline double lcalc_to_double(const long double& x) { return x; }
+inline double lcalc_to_double(const long double& x) { return x; }
 inline double lcalc_to_double(const int& x) { return x; }
 inline double lcalc_to_double(const long long& x) { return x; }
 inline double lcalc_to_double(const short& x) { return x; }

license: mit


code:
Patch taken from the Sage packaging system.

diff --git a/include/Lcommon.h b/include/Lcommon.h
index 1b3be43..bf40532 100644
--- a/include/Lcommon.h
+++ b/include/Lcommon.h
@@ -48,7 +48,7 @@ const bool outputSeries=true;	  // Whether to output the coefficients or just th

 // Loop i from m to n
 // Useful in tidying up most for loops
-#define loop(i,m,n) for(typeof(m) i=(m); i!=(n); i++)
+#define loop(i,m,n) for(auto i=(m); i!=(n); i++)

 // A class for calculations involving polynomials of small degree
 // Not efficient enough for huge polynomials
diff --git a/include/Lcommon_ld.h b/include/Lcommon_ld.h
index 86ae4df..33c560c 100644
--- a/include/Lcommon_ld.h
+++ b/include/Lcommon_ld.h
@@ -53,7 +53,7 @@ const bool outputSeries=true;	  // Whether to output the coefficients or just th

 // Loop i from m to n
 // Useful in tidying up most for loops
-#define loop(i,m,n) for(typeof(m) i=(m); i!=(n); i++)
+#define loop(i,m,n) for(auto i=(m); i!=(n); i++)

 // A class for calculations involving polynomials of small degree
 // Not efficient enough for huge polynomials
diff --git a/include/Lglobals.h b/include/Lglobals.h
index 60002e4..ca2606c 100644
--- a/include/Lglobals.h
+++ b/include/Lglobals.h
@@ -24,9 +24,9 @@
 #ifndef Lglobals_H
 #define Lglobals_H

+#include <valarray>
 using namespace std;

-#include <valarray>
 #ifdef USE_MPFR
     #include "Lgmpfrxx.h"
     typedef mpfr_class Double;


code:
https://github.com/mm2/Little-CMS/commit/768f70ca405cd3159d990e962d54456773bb8cf8.patch

From 768f70ca405cd3159d990e962d54456773bb8cf8 Mon Sep 17 00:00:00 2001
From: Marti Maria <info@littlecms.com>
Date: Wed, 15 Aug 2018 20:07:56 +0200
Subject: [PATCH] Upgrade Visual studio 2017 15.8

- Upgrade to 15.8
- Add check on CGATS memory allocation (thanks to Quang Nguyen for
pointing out this)
---
 Projects/VC2017/jpegicc/jpegicc.vcxproj           |  1 +
 Projects/VC2017/lcms2_DLL/lcms2_DLL.vcxproj       |  2 +-
 Projects/VC2017/lcms2_static/lcms2_static.vcxproj |  2 +-
 Projects/VC2017/linkicc/linkicc.vcxproj           |  2 +-
 Projects/VC2017/psicc/psicc.vcxproj               |  2 +-
 Projects/VC2017/testbed/testbed.vcxproj           |  2 +-
 Projects/VC2017/tiffdiff/tiffdiff.vcxproj         |  2 +-
 Projects/VC2017/tifficc/tifficc.vcxproj           |  2 +-
 Projects/VC2017/transicc/transicc.vcxproj         |  1 +
 src/cmscgats.c                                    | 14 ++++++++++----
 10 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/Projects/VC2017/jpegicc/jpegicc.vcxproj b/Projects/VC2017/jpegicc/jpegicc.vcxproj
index ab26a53..39cfd00 100644
--- a/Projects/VC2017/jpegicc/jpegicc.vcxproj
+++ b/Projects/VC2017/jpegicc/jpegicc.vcxproj
@@ -22,6 +22,7 @@
     <ProjectGuid>{62812507-F926-4968-96A9-17678460AD90}</ProjectGuid>
     <RootNamespace>jpegicc</RootNamespace>
     <Keyword>Win32Proj</Keyword>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/lcms2_DLL/lcms2_DLL.vcxproj b/Projects/VC2017/lcms2_DLL/lcms2_DLL.vcxproj
index 4c8aa3f..d1bf3eb 100644
--- a/Projects/VC2017/lcms2_DLL/lcms2_DLL.vcxproj
+++ b/Projects/VC2017/lcms2_DLL/lcms2_DLL.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{8C51BE48-ADB8-4089-A9EC-F6BF993A0548}</ProjectGuid>
     <RootNamespace>lcms2_DLL</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/lcms2_static/lcms2_static.vcxproj b/Projects/VC2017/lcms2_static/lcms2_static.vcxproj
index 2a9988a..9fc05ce 100644
--- a/Projects/VC2017/lcms2_static/lcms2_static.vcxproj
+++ b/Projects/VC2017/lcms2_static/lcms2_static.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{71DEDE59-3F1E-486B-A899-4283000F76B5}</ProjectGuid>
     <RootNamespace>lcms2_static</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/linkicc/linkicc.vcxproj b/Projects/VC2017/linkicc/linkicc.vcxproj
index 30c2b4e..51586dd 100644
--- a/Projects/VC2017/linkicc/linkicc.vcxproj
+++ b/Projects/VC2017/linkicc/linkicc.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{FBFBE1DC-DB84-4BA1-9552-B4780F457849}</ProjectGuid>
     <RootNamespace>linkicc</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/psicc/psicc.vcxproj b/Projects/VC2017/psicc/psicc.vcxproj
index 9dcf89a..8f26e12 100644
--- a/Projects/VC2017/psicc/psicc.vcxproj
+++ b/Projects/VC2017/psicc/psicc.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{EF6A8851-65FE-46F5-B9EF-14F0B671F693}</ProjectGuid>
     <RootNamespace>psicc</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/testbed/testbed.vcxproj b/Projects/VC2017/testbed/testbed.vcxproj
index 0af3762..3f6aea3 100644
--- a/Projects/VC2017/testbed/testbed.vcxproj
+++ b/Projects/VC2017/testbed/testbed.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{928A3A2B-46EF-4279-959C-513B3652FF0E}</ProjectGuid>
     <RootNamespace>testbed</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/tiffdiff/tiffdiff.vcxproj b/Projects/VC2017/tiffdiff/tiffdiff.vcxproj
index 7edfe28..3a6d837 100644
--- a/Projects/VC2017/tiffdiff/tiffdiff.vcxproj
+++ b/Projects/VC2017/tiffdiff/tiffdiff.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{75B91835-CCD7-48BE-A606-A9C997D5DBEE}</ProjectGuid>
     <RootNamespace>tiffdiff</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/tifficc/tifficc.vcxproj b/Projects/VC2017/tifficc/tifficc.vcxproj
index cd9f04c..5ef954f 100644
--- a/Projects/VC2017/tifficc/tifficc.vcxproj
+++ b/Projects/VC2017/tifficc/tifficc.vcxproj
@@ -22,7 +22,7 @@
     <ProjectGuid>{2256DE16-ED92-4A6F-9C54-F65BB61E64A2}</ProjectGuid>
     <RootNamespace>tifficc</RootNamespace>
     <Keyword>Win32Proj</Keyword>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/Projects/VC2017/transicc/transicc.vcxproj b/Projects/VC2017/transicc/transicc.vcxproj
index d9b77c6..b3173d8 100644
--- a/Projects/VC2017/transicc/transicc.vcxproj
+++ b/Projects/VC2017/transicc/transicc.vcxproj
@@ -22,6 +22,7 @@
     <ProjectGuid>{9EE22D66-C849-474C-9ED5-C3E141DAB160}</ProjectGuid>
     <RootNamespace>transicc</RootNamespace>
     <Keyword>Win32Proj</Keyword>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
diff --git a/src/cmscgats.c b/src/cmscgats.c
index 1a87613..8c3e96d 100644
--- a/src/cmscgats.c
+++ b/src/cmscgats.c
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------------
 //
 //  Little Color Management System
-//  Copyright (c) 1998-2017 Marti Maria Saguer
+//  Copyright (c) 1998-2018 Marti Maria Saguer
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the "Software"),
@@ -1506,10 +1506,16 @@ void AllocateDataSet(cmsIT8* it8)
     t-> nSamples   = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
     t-> nPatches   = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));

-    t-> Data = (char**)AllocChunk (it8, ((cmsUInt32Number) t->nSamples + 1) * ((cmsUInt32Number) t->nPatches + 1) *sizeof (char*));
-    if (t->Data == NULL) {
+    if (t -> nSamples < 0 || t->nSamples > 0x7ffe || t->nPatches < 0 || t->nPatches > 0x7ffe)
+    {
+        SynError(it8, "AllocateDataSet: too much data");
+    }
+    else {
+        t->Data = (char**)AllocChunk(it8, ((cmsUInt32Number)t->nSamples + 1) * ((cmsUInt32Number)t->nPatches + 1) * sizeof(char*));
+        if (t->Data == NULL) {

-        SynError(it8, "AllocateDataSet: Unable to allocate data array");
+            SynError(it8, "AllocateDataSet: Unable to allocate data array");
+        }
     }

 }


code:
This patch fixes a failing unit test by feeding buildNormalizedPath to the
tzdata properly.  Three other tests are disabled, one assumes /root and the
two others use networking.  Not bad out of almost 700 tests!

by Pjotr Prins <pjotr.guix@thebird.nl>

--- a/std/datetime.d.orig      2016-11-24 01:13:52.584495545 +0100
+++ b/std/datetime.d   2016-11-24 01:17:09.655306728 +0100
@@ -28081,22 +28081,24 @@
         import std.range : retro;
         import std.format : format;

-        name = strip(name);
-
         enforce(tzDatabaseDir.exists(), new DateTimeException(format("Directory %s does not exist.", tzDatabaseDir)));
         enforce(tzDatabaseDir.isDir, new DateTimeException(format("%s is not a directory.", tzDatabaseDir)));

         version(Android)
         {
+            name = strip(name);
             auto tzfileOffset = name in tzdataIndex(tzDatabaseDir);
             enforce(tzfileOffset, new DateTimeException(format("The time zone %s is not listed.", name)));
             string tzFilename = separate_index ? "zoneinfo.dat" : "tzdata";
             immutable file = buildNormalizedPath(tzDatabaseDir, tzFilename);
         }
         else
-            immutable file = buildNormalizedPath(tzDatabaseDir, name);
+        {
+            auto filename = "./" ~ strip(name); // make sure the prefix is not stripped
+            immutable file = buildNormalizedPath(tzDatabaseDir, filename);
+        }

-        enforce(file.exists(), new DateTimeException(format("File %s does not exist.", file)));
+        enforce(file.exists(), new DateTimeException(format("File %s does not exist in %s.", file, tzDatabaseDir)));
         enforce(file.isFile, new DateTimeException(format("%s is not a file.", file)));

         auto tzFile = File(file);
diff --git a/std/path.d b/std/path.d
index 254d8f0..b0fc04d 100644
--- a/std/path.d
+++ b/std/path.d
@@ -3080,8 +3080,11 @@ unittest
         }
         else
         {
+            pragma(msg, "test disabled on GNU Guix");
+/*
             assert(expandTilde("~root") == "/root", expandTilde("~root"));
             assert(expandTilde("~root/") == "/root/", expandTilde("~root/"));
+*/
         }
         assert(expandTilde("~Idontexist/hey") == "~Idontexist/hey");
     }
diff --git a/std/socket.d b/std/socket.d
index b85d1c9..7fbf346 100644
--- a/std/socket.d
+++ b/std/socket.d
@@ -859,6 +862,8 @@ class InternetHost

 unittest
 {
+    pragma(msg, "test disabled on GNU Guix");
+    /*
     InternetHost ih = new InternetHost;

     ih.getHostByAddr(0x7F_00_00_01);
@@ -889,6 +894,7 @@ unittest
         //      writefln("aliases[%d] = %s", i, s);
         // }
     });
+    */
 }


code:
diff --git a/std/socket.d b/std/socket.d
index 111cd17..6d23da9 100644
--- a/std/socket.d
+++ b/std/socket.d
@@ -448,7 +448,7 @@ class Protocol
 // Skip this test on Android because getprotobyname/number are
 // unimplemented in bionic.
 version(CRuntime_Bionic) {} else
-@safe unittest
+@safe version(hasNetwork) unittest
 {
     // import std.stdio : writefln;
     softUnittest({
@@ -770,7 +770,7 @@ class InternetHost
 }

 ///
-@safe unittest
+@safe version(hasNetwork) unittest
 {
     InternetHost ih = new InternetHost;


code:
From 68916cd7ffb49ece9126d13ef984595595a156c4 Mon Sep 17 00:00:00 2001
From: Raghav Gururajan <raghavgururajan@disroot.org>
Date: Wed, 29 Jul 2020 12:32:48 -0400
Subject: [PATCH] [PATCH]: Split installation of drill and examples.

---
 Makefile.in | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 442067de..9d2d5f4d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -14,6 +14,10 @@ libdir		= @libdir@
 includedir	= @includedir@
 sysconfdir      = @sysconfdir@
 doxygen		= @doxygen@
+drillbindir = @drillbindir@
+drillmandir = @drillmandir@
+examplesbindir = @examplesbindir@
+examplesmandir = @examplesmandir@
 pywrapdir       = $(srcdir)/contrib/python
 pyldnsxwrapdir  = $(srcdir)/contrib/ldnsx
 p5_dns_ldns_dir = $(srcdir)/contrib/DNS-LDNS
@@ -154,16 +158,16 @@ drill/drill.1: $(srcdir)/drill/drill.1.in
 	$(edit) $(srcdir)/drill/drill.1.in > drill/drill.1

 install-drill: drill/drill drill/drill.1
-	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
-	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)
-	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
-	$(LIBTOOL) --mode=install cp drill/drill $(DESTDIR)$(bindir)
-	$(INSTALL) -m 644 drill/drill.1 $(DESTDIR)$(mandir)/man1/drill.1
+	$(INSTALL) -m 755 -d $(drillbindir)
+	$(INSTALL) -m 755 -d $(drillmandir)
+	$(INSTALL) -m 755 -d $(drillmandir)/man1
+	$(LIBTOOL) --mode=install cp drill/drill $(drillbindir)
+	$(INSTALL) -m 644 drill/drill.1 $(drillmandir)/man1/drill.1

 uninstall-drill:
-	rm -f $(DESTDIR)$(bindir)/drill $(DESTDIR)$(mandir)/man1/drill.1
-	test ! -d $(DESTDIR)$(mandir) || rmdir -p $(DESTDIR)$(mandir)/man1 || :;
-	test ! -d $(DESTDIR)$(bindir) || rmdir -p $(DESTDIR)$(bindir) || : ;
+	rm -f $(drillbindir)/drill $(drillmandir)/man1/drill.1
+	test ! -d $(drillmandir) || rmdir -p $(drillmandir)/man1 || :;
+	test ! -d $(drillbindir) || rmdir -p $(drillbindir) || : ;

 clean-drill:
 	$(LIBTOOL) --mode clean rm -f $(DRILL_LOBJS) drill/drill drill/drill.1
@@ -202,23 +206,23 @@ examples/ldns-verify-zone.1: $(srcdir)/examples/ldns-verify-zone.1.in
 	$(edit) $(srcdir)/examples/ldns-verify-zone.1.in > examples/ldns-verify-zone.1

 install-examples: $(EXAMPLE_PROGS) $(TESTNS) $(LDNS_DPA) $(LDNS_DANE) $(EX_SSL_PROGS) examples/ldns-dane.1 examples/ldns-verify-zone.1
-	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
-	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)
-	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
+	$(INSTALL) -m 755 -d $(examplesbindir)
+	$(INSTALL) -m 755 -d $(examplesmandir)
+	$(INSTALL) -m 755 -d $(examplesmandir)/man1
 	for p in $(EXAMPLE_PROGS) $(TESTNS) $(LDNS_DPA) $(LDNS_DANE) $(EX_SSL_PROGS) ; do \
-		$(LIBTOOL) --mode=install cp $$p $(DESTDIR)$(bindir) ; \
+		$(LIBTOOL) --mode=install cp $$p $(examplesbindir) ; \
 		if test -f $$p.1 ; \
-		then $(INSTALL) -m 644 $$p.1 $(DESTDIR)$(mandir)/man1 ; \
-		else $(INSTALL) -m 644 $(srcdir)/$$p.1 $(DESTDIR)$(mandir)/man1 ; \
+		then $(INSTALL) -m 644 $$p.1 $(examplesmandir)/man1 ; \
+		else $(INSTALL) -m 644 $(srcdir)/$$p.1 $(examplesmandir)/man1 ; \
 		fi ; \
 	done

 uninstall-examples:
 	for p in $(EX_PROGS_BASENM) ; do \
-		rm -f $(DESTDIR)$(bindir)/$$p $(DESTDIR)$(mandir)/man1/$$p.1 ;\
+		rm -f $(examplesbindir)/$$p $(examplesmandir)/man1/$$p.1 ;\
 	done
-	test ! -d $(DESTDIR)$(mandir) || rmdir -p $(DESTDIR)$(mandir)/man1 || :;
-	test ! -d $(DESTDIR)$(bindir) || rmdir -p $(DESTDIR)$(bindir) || : ;
+	test ! -d $(examplesmandir) || rmdir -p $(examplesmandir)/man1 || :;
+	test ! -d $(examplesbindir) || rmdir -p $(examplesbindir) || : ;

 clean-examples:
 	$(LIBTOOL) --mode clean rm -f $(EXAMPLE_PROGS)
--
2.27.0


code:
Use shared gtest instead of submodule

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 617e4b2..2857875 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
 include(GNUInstallDirs)

 project(leelaz)
-add_subdirectory(gtest EXCLUDE_FROM_ALL) # We don't want to install gtest, exclude it from `all`

 # Required Packages
 set(Boost_MIN_VERSION "1.58.0")
@@ -27,6 +26,7 @@ find_package(Boost 1.58.0 REQUIRED program_options filesystem)
 find_package(Threads REQUIRED)
 find_package(ZLIB REQUIRED)
 find_package(OpenCL REQUIRED)
+find_package(GTest REQUIRED)
 # We need OpenBLAS for now, because we make some specific
 # calls. Ideally we'd use OpenBLAS is possible and fall back to
 # not doing those calls if it's not present.
@@ -93,6 +93,7 @@ include_directories(${IncludePath})
 include_directories(${Boost_INCLUDE_DIRS})
 include_directories(${OpenCL_INCLUDE_DIRS})
 include_directories(${ZLIB_INCLUDE_DIRS})
+include_directories(${GTEST_INCLUDE_DIRS})

 if((UNIX AND NOT APPLE) OR WIN32)
     include_directories(${BLAS_INCLUDE_DIRS})
@@ -141,7 +142,8 @@ target_link_libraries(tests ${Boost_LIBRARIES})
 target_link_libraries(tests ${BLAS_LIBRARIES})
 target_link_libraries(tests ${OpenCL_LIBRARIES})
 target_link_libraries(tests ${ZLIB_LIBRARIES})
-target_link_libraries(tests gtest_main ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(tests ${GTEST_BOTH_LIBRARIES})
+target_link_libraries(tests ${CMAKE_THREAD_LIBS_INIT})

 include(GetGitRevisionDescription)
 git_describe(VERSION --tags)


code:
Avoid usage of PATH_MAX.

Submitted to bug-less@gnu.org.

From ef652341ed8b2c14ac40312ccd4ed329cb69fd0c Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <janneke@gnu.org>
Date: Sat, 7 Mar 2020 14:57:19 +0100
Subject: [PATCH] Avoid usage of PATH_MAX.

* filename.c (lrealpath): Have realpath allocate the buffer.  Fixes
compilation on the Hurd and avoids possible buffer overflow on other
systems.
---
 filename.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/filename.c b/filename.c
index e420837..faa71b0 100644
--- a/filename.c
+++ b/filename.c
@@ -795,9 +795,9 @@ lrealpath(path)
 	char *path;
 {
 #if HAVE_REALPATH
-	char rpath[PATH_MAX];
-	if (realpath(path, rpath) != NULL)
-		return (save(rpath));
+	char *rpath = NULL;
+	if ((rpath = realpath(path, rpath)) != NULL)
+		return (rpath);
 #endif
 	return (save(path));
 }
--
2.24.0


code:
From 3e858cc87f2f8b7dc514a8ad7709c1f47f1f4cde Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Wed, 17 Jun 2020 23:20:53 -0400
Subject: [PATCH] tests: Fix tests on non-x86_64 platforms.

On platform other than x86_64 such as aarch64-linux or i686-linux,
some double comparisons would fail.

See <http://issues.guix.gnu.org/41827>.

* tests/bezier-test.cpp: (Casteljau): Replace EXPECT_EQ by
EXPECT_near.
(Subdivide): Replace EXPECT_EQ by EXPECT_DOUBLE_EQ.
(Portion): Replace EXPECT_EQ by EXPECT_near.
* tests/ellipse-test.cpp (BezierIntersection): Lower error tolerance
from 6e-13 to 6e-12.
(LineIntersection): Replace EXPECT_DOUBLE_EQ by EXPECT_NEAR.
* tests/line-test.cpp (Reflection): Replace EXPECT_FLOAT_EQ BY
EXPECT_near.
(Coefficients): Skip test.
* tests/parallelogram-test.cpp (area): Replace EXPECT_EQ by
EXPECT_DOUBLE_EQ.
---
 tests/bezier-test.cpp        | 31 +++++++++++++++++--------------
 tests/ellipse-test.cpp       | 11 ++++++-----
 tests/line-test.cpp          | 11 +++++++----
 tests/parallelogram-test.cpp |  8 ++++----
 4 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/tests/bezier-test.cpp b/tests/bezier-test.cpp
index 4054a654..46209f40 100644
--- a/tests/bezier-test.cpp
+++ b/tests/bezier-test.cpp
@@ -152,11 +152,13 @@ TEST_F(BezierTest, Casteljau) {
         EXPECT_vector_equal(right2, right);

         double vnone = casteljau_subdivision<double>(t, &wiggle[0], NULL, NULL, wiggle.order());
-        EXPECT_EQ(vnone, vok);
+        EXPECT_near(vnone, vok, 1e-12);
     }
 }

 TEST_F(BezierTest, Portion) {
+    constexpr Coord eps{1e-12};
+
     for (unsigned i = 0; i < 10000; ++i) {
         double from = g_random_double_range(0, 1);
         double to = g_random_double_range(0, 1);
@@ -165,8 +167,8 @@ TEST_F(BezierTest, Portion) {
             Bezier result = portion(input, from, to);

             // the endpoints must correspond exactly
-            EXPECT_EQ(result.at0(), input.valueAt(from));
-            EXPECT_EQ(result.at1(), input.valueAt(to));
+            EXPECT_near(result.at0(), input.valueAt(from), eps);
+            EXPECT_near(result.at1(), input.valueAt(to), eps);
         }
     }
 }
@@ -181,16 +183,16 @@ TEST_F(BezierTest, Subdivide) {

             // the endpoints must correspond exactly
             // moreover, the subdivision point must be exactly equal to valueAt(t)
-            EXPECT_EQ(result.first.at0(), input.at0());
-            EXPECT_EQ(result.first.at1(), result.second.at0());
-            EXPECT_EQ(result.second.at0(), input.valueAt(t));
-            EXPECT_EQ(result.second.at1(), input.at1());
+            EXPECT_DOUBLE_EQ(result.first.at0(), input.at0());
+            EXPECT_DOUBLE_EQ(result.first.at1(), result.second.at0());
+            EXPECT_DOUBLE_EQ(result.second.at0(), input.valueAt(t));
+            EXPECT_DOUBLE_EQ(result.second.at1(), input.at1());

             // ditto for valueAt
-            EXPECT_EQ(result.first.valueAt(0), input.valueAt(0));
-            EXPECT_EQ(result.first.valueAt(1), result.second.valueAt(0));
-            EXPECT_EQ(result.second.valueAt(0), input.valueAt(t));
-            EXPECT_EQ(result.second.valueAt(1), input.valueAt(1));
+            EXPECT_DOUBLE_EQ(result.first.valueAt(0), input.valueAt(0));
+            EXPECT_DOUBLE_EQ(result.first.valueAt(1), result.second.valueAt(0));
+            EXPECT_DOUBLE_EQ(result.second.valueAt(0), input.valueAt(t));
+            EXPECT_DOUBLE_EQ(result.second.valueAt(1), input.valueAt(1));

             if (result.first.at1() != result.second.at0()) {
                 errors.push_back(std::pair<Bezier,double>(input, t));
@@ -271,9 +273,10 @@ TEST_F(BezierTest, Deflate) {
     EXPECT_FLOAT_EQ(0, b.at0());
     b = b.deflate();
     const double rootposition = (0.5-0.25) / (1-0.25);
-    EXPECT_FLOAT_EQ(0, b.valueAt(rootposition));
+    constexpr Coord eps{1e-12};
+    EXPECT_near(0.0, b.valueAt(rootposition), eps);
     b = b.subdivide(rootposition).second;
-    EXPECT_FLOAT_EQ(0, b.at0());
+    EXPECT_near(0.0, b.at0(), eps);
 }

 TEST_F(BezierTest, Roots) {
@@ -364,7 +367,7 @@ TEST_F(BezierTest, Operators) {
         for(int i = 0; i <= 16; i++) {
             double t = i/16.0;
             double b = B.valueAt(t);
-            EXPECT_FLOAT_EQ(b*b, product.valueAt(t));
+            EXPECT_near(b*b, product.valueAt(t), 1e-12);
         }
     }
 }
diff --git a/tests/ellipse-test.cpp b/tests/ellipse-test.cpp
index 561c285a..8e4de12c 100644
--- a/tests/ellipse-test.cpp
+++ b/tests/ellipse-test.cpp
@@ -158,13 +158,14 @@ TEST(EllipseTest, LineIntersection) {
     std::vector<ShapeIntersection> xs = e.intersect(l);

     ASSERT_EQ(xs.size(), 2ul);
-    EXPECT_FLOAT_EQ(xs[0].point()[X], 0);
-    EXPECT_FLOAT_EQ(xs[0].point()[Y], -2);
-    EXPECT_FLOAT_EQ(xs[1].point()[X], 9./5);
-    EXPECT_FLOAT_EQ(xs[1].point()[Y], 8./5);

     // due to numeric imprecision when evaluating Ellipse,
     // the points may deviate by around 2e-16
+    EXPECT_NEAR(xs[0].point()[X], 0, 1e-15);
+    EXPECT_NEAR(xs[0].point()[Y], -2, 1e-15);
+    EXPECT_NEAR(xs[1].point()[X], 9./5, 1e-15);
+    EXPECT_NEAR(xs[1].point()[Y], 8./5, 1e-15);
+
     EXPECT_intersections_valid(e, l, xs, 1e-15);
 }

@@ -199,7 +200,7 @@ TEST(EllipseTest, BezierIntersection) {
     std::vector<ShapeIntersection> xs = e.intersect(b);

     EXPECT_EQ(xs.size(), 2ul);
-    EXPECT_intersections_valid(e, b, xs, 6e-13);
+    EXPECT_intersections_valid(e, b, xs, 6e-12);
 }

 TEST(EllipseTest, Coefficients) {
diff --git a/tests/line-test.cpp b/tests/line-test.cpp
index 99546ddc..23991300 100644
--- a/tests/line-test.cpp
+++ b/tests/line-test.cpp
@@ -91,10 +91,12 @@ TEST(LineTest, Reflection) {

     Point testra = pa * reflecta;
     Point testrb = pb * reflectb;
-    EXPECT_FLOAT_EQ(testra[X], ra[X]);
-    EXPECT_FLOAT_EQ(testra[Y], ra[Y]);
-    EXPECT_FLOAT_EQ(testrb[X], rb[X]);
-    EXPECT_FLOAT_EQ(testrb[Y], rb[Y]);
+
+    constexpr Coord eps{1e-12};
+    EXPECT_near(testra[X], ra[X], eps);
+    EXPECT_near(testra[Y], ra[Y], eps);
+    EXPECT_near(testrb[X], rb[X], eps);
+    EXPECT_near(testrb[Y], rb[Y], eps);
 }

 TEST(LineTest, RotationToZero) {
@@ -115,6 +117,7 @@ TEST(LineTest, RotationToZero) {
 }

 TEST(LineTest, Coefficients) {
+    GTEST_SKIP() << "This test fails on i686-linux and aarch64-linux";
     std::vector<Line> lines;
     lines.push_back(Line(Point(1e9,1e9), Point(1,1)));
     //the case below will never work without normalizing the line
diff --git a/tests/parallelogram-test.cpp b/tests/parallelogram-test.cpp
index 8109eadd..70ccea13 100644
--- a/tests/parallelogram-test.cpp
+++ b/tests/parallelogram-test.cpp
@@ -106,13 +106,13 @@ TEST(ParallelogramTest, area)
 {
     Rect r(2, 4, 7, 8);
     Parallelogram p(r);
-    EXPECT_EQ(p.area(), r.area());
+    EXPECT_DOUBLE_EQ(p.area(), r.area());
     p *= Rotate(M_PI / 4.0); // 45°
-    EXPECT_EQ(p.area(), r.area());
+    EXPECT_DOUBLE_EQ(p.area(), r.area());
     p *= HShear(2);
-    EXPECT_EQ(p.area(), r.area());
+    EXPECT_DOUBLE_EQ(p.area(), r.area());
     p *= Scale(2);
-    EXPECT_EQ(p.area(), r.area() * 4);
+    EXPECT_DOUBLE_EQ(p.area(), r.area() * 4);
 }

 class ParallelogramTest
--
2.27.0


code:
Copied from Debian.

Description: Disabling -prefer-non-pic which enables -fPIC
Bug-Debian: http://bugs.debian.org/401590
Author: Daniel Baumann <daniel@debian.org>, Dmitrijs Ledkovs <dmitrij.ledkov@gmail.com>

---
 liba52/configure.incl |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

Index: a52dec-deb/liba52/configure.incl
===================================================================
--- a52dec-deb.orig/liba52/configure.incl	2009-12-05 02:52:12.000000000 +0000
+++ a52dec-deb/liba52/configure.incl	2009-12-05 03:23:45.000000000 +0000
@@ -1,9 +1,6 @@
 AC_SUBST([LIBA52_CFLAGS])
 AC_SUBST([LIBA52_LIBS])

-dnl avoid -fPIC when possible
-LIBA52_CFLAGS="$LIBA52_CFLAGS -prefer-non-pic"
-
 AC_ARG_ENABLE([double],
     [  --enable-double         use double-precision samples])
 if test x"$enable_double" = x"yes"; then


code:
Copied from Debian.

Description: Explicitely link against -lm
Bug-Debian: http://bugs.debian.org/553595
Author: Fabian Greffrath <fabian@debian-unofficial.org>, Dmitrijs Ledkovs <dmitrij.ledkov@gmail.com>

---
 libao/Makefile.am |    1 +
 src/Makefile.am   |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,9 +1,9 @@
-CFLAGS = @A52DEC_CFLAGS@
+AM_CFLAGS = @A52DEC_CFLAGS@

 bin_PROGRAMS = a52dec extract_a52
 a52dec_SOURCES = a52dec.c getopt.c gettimeofday.c
 a52dec_LDADD = $(top_builddir)/liba52/liba52.la \
-	       $(top_builddir)/libao/libao.a @LIBAO_LIBS@
+	       $(top_builddir)/libao/libao.a @LIBAO_LIBS@ -lm
 extract_a52_SOURCES = extract_a52.c getopt.c

 man_MANS = a52dec.1 extract_a52.1
--- a/liba52/Makefile.am
+++ b/liba52/Makefile.am
@@ -1,4 +1,4 @@
-CFLAGS = @CFLAGS@ @LIBA52_CFLAGS@
+AM_CFLAGS = @CFLAGS@ @LIBA52_CFLAGS@

 lib_LTLIBRARIES = liba52.la


code:
Copied from Debian.

Description: Sets the soname to liba52-$(VERSION).so
Bug-Debian: http://bugs.debian.org/401636
Author: Daniel Baumann <daniel@debian.org>, Dmitrijs Ledkovs <dmitrij.ledkov@gmail.com>

---
 liba52/Makefile.am |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Index: a52dec-deb/liba52/Makefile.am
===================================================================
--- a52dec-deb.orig/liba52/Makefile.am	2009-12-05 02:52:12.000000000 +0000
+++ a52dec-deb/liba52/Makefile.am	2009-12-05 03:23:47.000000000 +0000
@@ -4,6 +4,6 @@

 liba52_la_SOURCES = bitstream.c imdct.c bit_allocate.c parse.c downmix.c
 liba52_la_LIBADD = @LIBA52_LIBS@ -lm
-liba52_la_LDFLAGS = -no-undefined
+liba52_la_LDFLAGS = -no-undefined -release @VERSION@

 EXTRA_DIST = configure.incl a52_internal.h bitstream.h tables.h


code:
Copied from Debian.

From: Rodeo
Origin: https://github.com/HandBrake/HandBrake/blob/master/contrib/a52dec/A04-modern-gcc-cflags.patch

--- a52dec-0.7.4/configure.in.orig
+++ a52dec-0.7.4/configure.in
@@ -34,11 +34,11 @@
     case "$host" in
     i?86-* | k?-*)
 	case "$host" in
-	i386-*) OPT_CFLAGS="$CFLAGS -mcpu=i386";;
-	i486-*) OPT_CFLAGS="$CFLAGS -mcpu=i486";;
-	i586-*) OPT_CFLAGS="$CFLAGS -mcpu=pentium";;
-	i686-*) OPT_CFLAGS="$CFLAGS -mcpu=pentiumpro";;
-	k6-*)   OPT_CFLAGS="$CFLAGS -mcpu=k6";;
+	i386-*) OPT_CFLAGS="$CFLAGS -mtune=i386";;
+	i486-*) OPT_CFLAGS="$CFLAGS -mtune=i486";;
+	i586-*) OPT_CFLAGS="$CFLAGS -mtune=pentium";;
+	i686-*) OPT_CFLAGS="$CFLAGS -mtune=pentiumpro";;
+	k6-*)   OPT_CFLAGS="$CFLAGS -mtune=k6";;
 	esac
 	AC_TRY_CFLAGS([$OPT_CFLAGS],[CFLAGS=$OPT_CFLAGS]);;
     sparc-* | sparc64-*)


code:
This patch fixes the build of adb on linux.

Copied from archlinux repository:
https://git.archlinux.org/svntogit/community.git/tree/trunk/fix_build.patch?h=packages/android-tools

diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 75dcc86..867f3ec 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -25,6 +25,7 @@
 #endif

 #include <errno.h>
+#include <sys/syscall.h>

 #include <string>
 #include <vector>
@@ -831,7 +832,16 @@ static __inline__ int adb_is_absolute_host_path(const char* path) {

 static __inline__ unsigned long adb_thread_id()
 {
-    return (unsigned long)gettid();
+  // TODO: this function should be merged with GetThreadId
+#if defined(__BIONIC__)
+  return gettid();
+#elif defined(__APPLE__)
+  return syscall(SYS_thread_selfid);
+#elif defined(__linux__)
+  return syscall(__NR_gettid);
+#elif defined(_WIN32)
+  return GetCurrentThreadId();
+#endif
 }

 #endif /* !_WIN32 */
diff --git a/base/errors_unix.cpp b/base/errors_unix.cpp
index 296995e..48269b6 100644
--- a/base/errors_unix.cpp
+++ b/base/errors_unix.cpp
@@ -17,6 +17,7 @@
 #include "android-base/errors.h"

 #include <errno.h>
+#include <string.h>

 namespace android {
 namespace base {
diff --git a/base/file.cpp b/base/file.cpp
index da1adba..91a3901 100644
--- a/base/file.cpp
+++ b/base/file.cpp
@@ -20,6 +20,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <string.h>

 #include <string>

diff --git a/base/logging.cpp b/base/logging.cpp
index 1741871..e97c7f1 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -21,6 +21,7 @@
 #include "android-base/logging.h"

 #include <libgen.h>
+#include <string.h>

 // For getprogname(3) or program_invocation_short_name.
 #if defined(__ANDROID__) || defined(__APPLE__)


code:
Patch copied from:
https://android.googlesource.com/platform/system/core/+/e5dd71a290f664d3f3bf0dd8a4bad411dc7ad416

From e5dd71a290f664d3f3bf0dd8a4bad411dc7ad416 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <enh@google.com>
Date: Thu, 28 Jul 2016 15:15:28 -0700
Subject: [PATCH] libbase should use its own logging!

Not doing so led to us using a bogus log tag.

Bug: http://b/30281203
Change-Id: I3ac91758a1a043146c65f2ae0f36fcfbe372c30f
---
 base/file.cpp    | 11 +++++------
 base/logging.cpp |  3 +--
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/base/file.cpp b/base/file.cpp
index da1adba19..4e7ac82d1 100644
--- a/base/file.cpp
+++ b/base/file.cpp
@@ -24,9 +24,8 @@
 #include <string>

 #include "android-base/macros.h"  // For TEMP_FAILURE_RETRY on Darwin.
+#include "android-base/logging.h"
 #include "android-base/utf8.h"
-#define LOG_TAG "base.file"
-#include "cutils/log.h"
 #include "utils/Compat.h"

 namespace android {
@@ -86,22 +85,22 @@ bool WriteStringToFile(const std::string& content, const std::string& path,
   int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY;
   int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
   if (fd == -1) {
-    ALOGE("android::WriteStringToFile open failed: %s", strerror(errno));
+    PLOG(ERROR) << "android::WriteStringToFile open failed";
     return false;
   }

   // We do an explicit fchmod here because we assume that the caller really
   // meant what they said and doesn't want the umask-influenced mode.
   if (fchmod(fd, mode) == -1) {
-    ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno));
+    PLOG(ERROR) << "android::WriteStringToFile fchmod failed";
     return CleanUpAfterFailedWrite(path);
   }
   if (fchown(fd, owner, group) == -1) {
-    ALOGE("android::WriteStringToFile fchown failed: %s", strerror(errno));
+    PLOG(ERROR) << "android::WriteStringToFile fchown failed";
     return CleanUpAfterFailedWrite(path);
   }
   if (!WriteStringToFd(content, fd)) {
-    ALOGE("android::WriteStringToFile write failed: %s", strerror(errno));
+    PLOG(ERROR) << "android::WriteStringToFile write failed";
     return CleanUpAfterFailedWrite(path);
   }
   close(fd);
diff --git a/base/logging.cpp b/base/logging.cpp
index 769c266c9..959bb8b05 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -43,12 +43,11 @@

 #include "android-base/macros.h"
 #include "android-base/strings.h"
-#include "cutils/threads.h"

 // Headers for LogMessage::LogLine.
 #ifdef __ANDROID__
 #include <android/set_abort_message.h>
-#include "cutils/log.h"
+#include "log/log.h"
 #else
 #include <sys/types.h>
 #include <unistd.h>
--
2.11.0


code:
The tests in race_empty non-deterministically fail with the error message:

  ** (process:10183): WARNING **: Async activation error activating 'IDL:Empty:1.0' : 'System exception: IDL:Bonobo/GeneralError:1.0 : Child process did not give an error message, unknown failure occurred'
FAILED 3 of 17: async activation

--- a/tests/test-activation/bonobo-activation-test.c	2014-07-01 23:45:10.830466301 -0500
+++ b/tests/test-activation/bonobo-activation-test.c	2014-07-01 23:57:53.122485584 -0500
@@ -299,7 +299,7 @@
         g_assert (ORBit_small_get_connection_status (ac) ==
                   ORBIT_CONNECTION_CONNECTED);

-        race_empty (&ev);
+        passed+=2;


code:
# We insert a hook called "@SOUND_THEME_DIRECTORY@" where, at build time, we
# insert the directory of the package "sound-theme-freedesktop" in the store.

--- src/sound-theme-spec.c.orig	2015-01-11 13:13:29.520527358 +0100
+++ src/sound-theme-spec.c	2015-01-11 14:27:23.035046849 +0100
@@ -321,9 +321,13 @@
         const char *g;

         if (!(g = getenv("XDG_DATA_DIRS")) || *g == 0)
-                return "/usr/local/share:/usr/share";
-
-        return g;
+                return "@SOUND_THEME_DIRECTORY@";
+        else {
+                const char *stp = ":@SOUND_THEME_DIRECTORY@";
+                size_t len = strlen(stp) + strlen(g) + 1;
+                char *g2 = (char*) malloc(len);
+                return strcat(strcpy(g2, g), stp);
+        }
 }

 static int load_theme_dir(ca_theme_data *t, const char *name) {


code:
Only check for for relative path on virtio devices.  Otherwise it could
break driver loading in some circumstances, notably the IceCat sandbox.

https://gitlab.freedesktop.org/mesa/drm/-/issues/39

Taken from upstream:
https://gitlab.freedesktop.org/mesa/drm/-/commit/57df07572ce45a1b60bae6fb89770388d3abd6dd

diff --git a/xf86drm.c b/xf86drm.c
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3103,15 +3103,18 @@ static int drmParseSubsystemType(int maj, int min)
     int subsystem_type;

     snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
-    if (!realpath(path, real_path))
-        return -errno;
-    snprintf(path, sizeof(path), "%s", real_path);

     subsystem_type = get_subsystem_type(path);
+    /* Try to get the parent (underlying) device type */
     if (subsystem_type == DRM_BUS_VIRTIO) {
+        /* Assume virtio-pci on error */
+        if (!realpath(path, real_path))
+            return DRM_BUS_VIRTIO;
         strncat(path, "/..", PATH_MAX);
         subsystem_type = get_subsystem_type(path);
-    }
+        if (subsystem_type < 0)
+            return DRM_BUS_VIRTIO;
+     }
     return subsystem_type;
 #elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__)
     return DRM_BUS_PCI;
@@ -3920,6 +3923,7 @@ process_device(drmDevicePtr *device, const char *d_name,

     switch (subsystem_type) {
     case DRM_BUS_PCI:
+    case DRM_BUS_VIRTIO:
         return drmProcessPciDevice(device, node, node_type, maj, min,
                                    fetch_deviceinfo, flags);
     case DRM_BUS_USB:


code:
This is a combination of the following 4 commits:
https://github.com/libffi/libffi/commit/01a75ed76ea7e57f1b7a5c183e2b1e890e6aa0fd.patch
https://github.com/libffi/libffi/commit/6663047f56c2932a6b10a790f4ac6666dd181326.patch
https://github.com/libffi/libffi/commit/e50b9ef8b910fa642ef158f6642e60d54d7ad740.patch
https://github.com/libffi/libffi/commit/4d6d2866ae43e55325e8ee96561221804602cd7a.patch

From 2dbfa92a95e3bacabca431b89d2a5925e48a0e40 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <slyfox@gentoo.org>
Date: Thu, 28 Nov 2019 12:42:41 +0000

powerpc: fix build failure on power7 and older (#532)

Build failure looks as:
```
libtool: compile:  powerpc-unknown-linux-gnu-gcc \
    -O2 -mcpu=powerpc -mtune=powerpc -pipe ... -c src/powerpc/ffi.c ...
In file included from src/powerpc/ffi.c:33:
src/powerpc/ffi_powerpc.h:65:9: error: '__int128' is not supported on this target
   65 | typedef __int128 float128;
      |         ^~~~~~~~
```

The fix avoids using __int128 in favour of aligned char[16].

Closes: https://github.com/libffi/libffi/issues/531
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

Address platforms with no __int128.

powerpc64: Use memcpy to help platforms with no __int128. (#534)

Signed-off-by: Khem Raj <raj.khem@gmail.com>

Update powerpc sysv assembly for ffi_powerpc.h changes (#541)

Some of the flag bits were moved when adding powerpc64 vector support.

Fixes #536
---
 src/powerpc/ffi_linux64.c | 12 ++++++------
 src/powerpc/ffi_powerpc.h |  2 +-
 src/powerpc/sysv.S        | 12 +++++-------
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/powerpc/ffi_linux64.c b/src/powerpc/ffi_linux64.c
index de0d033..4d50878 100644
--- a/src/powerpc/ffi_linux64.c
+++ b/src/powerpc/ffi_linux64.c
@@ -547,9 +547,9 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
               if (next_arg.ul == gpr_end.ul)
                 next_arg.ul = rest.ul;
               if (vecarg_count < NUM_VEC_ARG_REGISTERS64 && i < nfixedargs)
-                *vec_base.f128++ = **p_argv.f128;
+		memcpy (vec_base.f128++, *p_argv.f128, sizeof (float128));
               else
-                *next_arg.f128 = **p_argv.f128;
+		memcpy (next_arg.f128, *p_argv.f128, sizeof (float128));
               if (++next_arg.f128 == gpr_end.f128)
                 next_arg.f128 = rest.f128;
               vecarg_count++;
@@ -680,9 +680,9 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
                     {
                       if (vecarg_count < NUM_VEC_ARG_REGISTERS64
                           && i < nfixedargs)
-                        *vec_base.f128++ = *arg.f128++;
+		        memcpy (vec_base.f128++, arg.f128, sizeof (float128));
                       else
-                        *next_arg.f128 = *arg.f128++;
+		        memcpy (next_arg.f128, arg.f128++, sizeof (float128));
                       if (++next_arg.f128 == gpr_end.f128)
                         next_arg.f128 = rest.f128;
                       vecarg_count++;
@@ -986,9 +986,9 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif,
                   do
                     {
                       if (pvec < end_pvec && i < nfixedargs)
-                        *to.f128 = *pvec++;
+		        memcpy (to.f128, pvec++, sizeof (float128));
                       else
-                        *to.f128 = *from.f128;
+		        memcpy (to.f128, from.f128, sizeof (float128));
                       to.f128++;
                       from.f128++;
                     }
diff --git a/src/powerpc/ffi_powerpc.h b/src/powerpc/ffi_powerpc.h
index 5ee2a70..8e2f2f0 100644
--- a/src/powerpc/ffi_powerpc.h
+++ b/src/powerpc/ffi_powerpc.h
@@ -62,7 +62,7 @@ typedef _Float128 float128;
 #elif defined(__FLOAT128__)
 typedef __float128 float128;
 #else
-typedef __int128 float128;
+typedef char float128[16] __attribute__((aligned(16)));
 #endif

 void FFI_HIDDEN ffi_closure_SYSV (void);
diff --git a/src/powerpc/sysv.S b/src/powerpc/sysv.S
index 1474ce7..df97734 100644
--- a/src/powerpc/sysv.S
+++ b/src/powerpc/sysv.S
@@ -104,17 +104,16 @@ ENTRY(ffi_call_SYSV)
 	bctrl

 	/* Now, deal with the return value.  */
-	mtcrf	0x01,%r31 /* cr7  */
+	mtcrf	0x03,%r31 /* cr6-cr7  */
 	bt-	31,L(small_struct_return_value)
 	bt-	30,L(done_return_value)
 #ifndef __NO_FPRS__
 	bt-	29,L(fp_return_value)
 #endif
 	stw	%r3,0(%r30)
-	bf+	28,L(done_return_value)
+	bf+	27,L(done_return_value)
 	stw	%r4,4(%r30)
-	mtcrf	0x02,%r31 /* cr6  */
-	bf	27,L(done_return_value)
+	bf	26,L(done_return_value)
 	stw     %r5,8(%r30)
 	stw	%r6,12(%r30)
 	/* Fall through...  */
@@ -145,10 +144,9 @@ L(done_return_value):
 #ifndef __NO_FPRS__
 L(fp_return_value):
 	.cfi_restore_state
-	bf	28,L(float_return_value)
+	bf	27,L(float_return_value)
 	stfd	%f1,0(%r30)
-	mtcrf   0x02,%r31 /* cr6  */
-	bf	27,L(done_return_value)
+	bf	26,L(done_return_value)
 	stfd	%f2,8(%r30)
 	b	L(done_return_value)
 L(float_return_value):
--
2.26.0


code:
From 678ffd97db2d63cf6856428bea65a93e069f812f Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 4 Sep 2019 16:11:37 +0200
Subject: [PATCH 1/2] Adapt test script for PROJ 6.2 EPSG database (fixes #22)

---
 libgeotiff/test/testlistgeo          | 8 +++++++-
 libgeotiff/test/testlistgeo_out.dist | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libgeotiff/test/testlistgeo b/libgeotiff/test/testlistgeo
index 7fb4a2f..571f5d0 100755
--- a/test/testlistgeo
+++ b/test/testlistgeo
@@ -210,10 +210,15 @@ echo "Testing listgeo equidistant_cylindrical.tif" >> ${OUT}
 $EXE ${DATA_DIR}/equidistant_cylindrical.tif >>${OUT}
 echo "" >>${OUT}

+# Normalize for results depending on the exact version of PROJ / EPSG database
+sed "s/ETRS89-extended/ETRS89/g" < ${OUT} > ${OUT}.tmp
+mv ${OUT}.tmp ${OUT}
+
+sed "s/ETRS89-extended/ETRS89/g" < ${TEST_CLI_DIR}/testlistgeo_out.dist > testlistgeo_out.dist.tmp

 # do 'diff' with distribution results
 echo "diff ${OUT} with testlistgeo_out.dist"
-diff -u ${OUT} ${TEST_CLI_DIR}/testlistgeo_out.dist
+diff -u ${OUT} testlistgeo_out.dist.tmp
 if [ $? -ne 0 ] ; then
     echo  ""
     echo "PROBLEMS HAVE OCCURRED"
@@ -224,6 +229,7 @@ else
     echo "TEST OK"
     echo "test file ${OUT} removed"
     echo
+    rm testlistgeo_out.dist.tmp
     /bin/rm -f ${OUT}
     exit 0
 fi
diff --git a/libgeotiff/test/testlistgeo_out.dist b/libgeotiff/test/testlistgeo_out.dist
index 68a948c..c157f00 100644
--- a/test/testlistgeo_out.dist
+++ b/test/testlistgeo_out.dist
@@ -1738,11 +1738,11 @@ Geotiff_Information:
    Keyed_Information:
       GTModelTypeGeoKey (Short,1): ModelTypeProjected
       GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
-      ProjectedCSTypeGeoKey (Short,1): Code-3035 (ETRS89 / LAEA Europe)
+      ProjectedCSTypeGeoKey (Short,1): Code-3035 (ETRS89-extended / LAEA Europe)
       End_Of_Keys.
    End_Of_Geotiff.

-PCS = 3035 (ETRS89 / LAEA Europe)
+PCS = 3035 (ETRS89-extended / LAEA Europe)
 Projection = 19986 (Europe Equal Area 2001)
 Projection Method: CT_LambertAzimEqualArea
    ProjCenterLatGeoKey: 52.000000 ( 52d 0' 0.00"N)

From 15af10648c4cb7b4c55cbe08caaf9884c1d156d9 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 4 Sep 2019 19:13:11 +0200
Subject: [PATCH 2/2] appveyor.yml: build vcpkg from source to fix issue with
 VS2015


code:
The Clar test framework has a bug whereby it skips the parsing phase
on files with mtime=0.

Reported upstream at <https://github.com/vmg/clar/pull/78>.

diff --git a/tests/generate.py b/tests/generate.py
index b639c8f..111ca41 100644
--- a/tests/generate.py
+++ b/tests/generate.py
@@ -63,3 +63,3 @@ class Module(object):

-        self.mtime = 0
+        self.mtime = None # Guix sets all file mtimes to '0'
         self.enabled = True


code:
Remove non-UTF-8 character (this is a NO-BREAK SPACE character, encoded in
ISO-8859-1) to fix build failure with 'glib-mkenums' in GLib 2.54.2+.

Patch from <https://github.com/macports/macports-ports/commit/1f3efc8e65cc060d1701407bd1e56e62e6bd9c55>.

--- a/libgnome/gnome-config.h	2009-04-23 04:29:13.000000000 -0500
+++ b/libgnome/gnome-config.h	2017-10-04 02:17:22.000000000 -0500
@@ -270,7 +270,7 @@ void gnome_config_clean_key_ (const char
 #define gnome_config_private_clean_key(path) \
 	(gnome_config_clean_key_((path),TRUE))

-/* returns the true filename of the config file�*/
+/* returns the true filename of the config file */
 #define gnome_config_get_real_path(path) \
 	(g_build_filename (gnome_user_dir_get(),(path),NULL))
 #define gnome_config_private_get_real_path(path) \


code:
Fixes build with Python >= 3.6:

------
Making all in libgnomeui
make[2]: Entering directory '/tmp/guix-build-libgnomeui-2.24.5.drv-0/libgnomeui-2.24.5/libgnomeui'
  GEN    stamp-gnome-marshal.h
  GEN    stamp-gnometypebuiltins.h
INFO: Reading ./gnome-marshal.list...
  GEN    gnome-marshal.h
Traceback (most recent call last):
  File "/gnu/store/...-glib-2.54.2-bin/bin/glib-mkenums", line 688, in <module>
    process_file(fname)
  File "/gnu/store/...-glib-2.54.2-bin/bin/glib-mkenums", line 420, in process_file
    line = curfile.readline()
  File "/gnu/store/...-python-3.6.3/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 1009: invalid continuation byte
make[2]: *** [Makefile:1109: stamp-gnometypebuiltins.h] Error 1
make[2]: Leaving directory '/tmp/guix-build-libgnomeui-2.24.5.drv-0/libgnomeui-2.24.5/libgnomeui'
make[1]: *** [Makefile:369: all-recursive] Error 1
make[1]: Leaving directory '/tmp/guix-build-libgnomeui-2.24.5.drv-0/libgnomeui-2.24.5'
make: *** [Makefile:296: all] Error 2
------

Patch copied from upstream source repository:

https://git.gnome.org/browse/libgnomeui/commit/?id=30334c28794ef85d8973f4ed0779b5ceed6594f2

From 30334c28794ef85d8973f4ed0779b5ceed6594f2 Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Mon, 7 Aug 2017 13:15:26 -0400
Subject: [PATCH] gnome-scores.h: Convert to UTF-8

The new Python `glib-mkenums` barfs on ISO-8859-1 input.
---
 libgnomeui/gnome-scores.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgnomeui/gnome-scores.h b/libgnomeui/gnome-scores.h
index 911b12d1..4e641d22 100644
--- a/libgnomeui/gnome-scores.h
+++ b/libgnomeui/gnome-scores.h
@@ -27,7 +27,7 @@
  * "High Scores" Widget
  *
  * AUTHOR:
- * Horacio J. Pe�a <horape@compendium.com.ar>
+ * Horacio J. Peña <horape@compendium.com.ar>
  *
  * This is free software (under the terms of the GNU LGPL)
  *


code:
Description: Fix function signature
Author: Mathieu Malaterre <malat@debian.org>
Origin: upstream, https://jxrlib.codeplex.com/SourceControl/changeset/04cf339385b8196f98025b43a366a0790deac994
Bug-Debian: http://bugs.debian.org/748590

--- jxrlib-1.1.orig/image/decode/JXRTranscode.c
+++ jxrlib-1.1/image/decode/JXRTranscode.c
@@ -47,7 +47,7 @@ EXTERN_C Void FreeCodingContextDec(CWMIm
 EXTERN_C Int StrEncInit(CWMImageStrCodec *);
 EXTERN_C Void StrIOEncTerm(CWMImageStrCodec *);
 EXTERN_C Void FreeCodingContextEnc(CWMImageStrCodec *);
-EXTERN_C Void encodeMB(CWMImageStrCodec *, Int, Int);
+EXTERN_C Int encodeMB(CWMImageStrCodec *, Int, Int);
 EXTERN_C Int  writeIndexTableNull(CWMImageStrCodec *);
 EXTERN_C Void writePacketHeader(BitIOInfo *, U8, U8);


code:
Description: Fix typos and remove some warnings
Author: Mathieu Malaterre <malat@debian.org>

Index: jxrlib-1.1/jxrencoderdecoder/JxrEncApp.c
===================================================================
--- jxrlib-1.1.orig/jxrencoderdecoder/JxrEncApp.c
+++ jxrlib-1.1/jxrencoderdecoder/JxrEncApp.c
@@ -578,7 +578,7 @@ main(int argc, char* argv[])

     //================================
     Call(PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION));
-    Call(pCodecFactory->CreateCodec(&IID_PKImageWmpEncode, &pEncoder));
+    Call(pCodecFactory->CreateCodec(&IID_PKImageWmpEncode, (void**)&pEncoder));

     //----------------------------------------------------------------
     Call(PKCreateTestFactory(&pTestFactory, WMP_SDK_VERSION));
Index: jxrlib-1.1/jxrgluelib/JXRMeta.h
===================================================================
--- jxrlib-1.1.orig/jxrgluelib/JXRMeta.h
+++ jxrlib-1.1/jxrgluelib/JXRMeta.h
@@ -34,7 +34,7 @@

 #ifndef UNREFERENCED_PARAMETER
 #define UNREFERENCED_PARAMETER(P) { (P) = (P); }
-#endif UNREFERENCED_PARAMETER
+#endif /*UNREFERENCED_PARAMETER*/

 //================================================================
 // Container


code:
From 732861dda9c466841a09329a0b2c992f2b78c40a Mon Sep 17 00:00:00 2001
From: Hartmut Goebel <h.goebel@crazy-compilers.com>
Date: Tue, 21 Jan 2020 23:15:23 +0100
Subject: [PATCH] Fix missing link libraries.

See <https://phabricator.kde.org/D26818>

These are only actually missing if the libraries reside in different
prefixes, as it is the case in Guix or Nix.
---
 src/ksieveui/autocreatescripts/tests/CMakeLists.txt  | 2 ++
 src/ksieveui/scriptsparsing/autotests/CMakeLists.txt | 2 +-
 src/ksieveui/scriptsparsing/tests/CMakeLists.txt     | 8 ++++++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/ksieveui/autocreatescripts/tests/CMakeLists.txt b/src/ksieveui/autocreatescripts/tests/CMakeLists.txt
index 8a482b4..c43216c 100644
--- a/src/ksieveui/autocreatescripts/tests/CMakeLists.txt
+++ b/src/ksieveui/autocreatescripts/tests/CMakeLists.txt
@@ -15,6 +16,7 @@ set(parsingscript_gui_SRCS parsingscript_gui.cpp ../../tests/capability.cpp)
 add_executable(parsingscript_gui ${parsingscript_gui_SRCS})
 target_link_libraries(parsingscript_gui
   KF5::KIOCore
+  KF5::SyntaxHighlighting
   KF5::KSieveUi
   KF5::KSieve
   KF5::PimCommon
diff --git a/src/ksieveui/scriptsparsing/autotests/CMakeLists.txt b/src/ksieveui/scriptsparsing/autotests/CMakeLists.txt
index e41a74e..31703ef 100644
--- a/src/ksieveui/scriptsparsing/autotests/CMakeLists.txt
+++ b/src/ksieveui/scriptsparsing/autotests/CMakeLists.txt
@@ -5,7 +5,7 @@ macro(add_sieveeditor_xmlprintingscriptbuilding _source _extrasource)
     ecm_add_test(${_test}
         TEST_NAME ${_name}
         NAME_PREFIX "sieveeditor-xmlprintingscriptbuilding-"
-        LINK_LIBRARIES Qt5::Test KF5::I18n KF5::KSieveUi
+        LINK_LIBRARIES Qt5::Test KF5::I18n KF5::KSieveUi KF5::SyntaxHighlighting
         )
 endmacro()
 add_sieveeditor_xmlprintingscriptbuilding(xmlprintingscriptbuildertest.cpp "" "")
diff --git a/src/ksieveui/scriptsparsing/tests/CMakeLists.txt b/src/ksieveui/scriptsparsing/tests/CMakeLists.txt
index a252039..99a1aaa 100644
--- a/src/ksieveui/scriptsparsing/tests/CMakeLists.txt
+++ b/src/ksieveui/scriptsparsing/tests/CMakeLists.txt
@@ -9,5 +9,9 @@ set(xmlsieveparsing_SRCS
 )

 add_executable(xmlsieveparsing ${xmlsieveparsing_SRCS} )
-target_link_libraries(xmlsieveparsing   KF5::KSieveUi KF5::KSieve KF5::I18n)
-
+target_link_libraries(xmlsieveparsing
+  KF5::KSieveUi
+  KF5::SyntaxHighlighting
+  KF5::KSieve
+  KF5::I18n
+)
--
2.21.1


code:
From 52d44cdbc307d4e2ffc3ebe674745eb9d43ec337 Mon Sep 17 00:00:00 2001
From: Christian Egli <christian.egli@sbs.ch>
Date: Mon, 10 Aug 2020 16:08:17 +0200
Subject: [PATCH] Some math over and under tests now actually pass

with the newest liblouis
---
 tests/Makefile.am | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 157b005..932a5d0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -321,10 +321,6 @@ XFAIL_TESTS +=					\
 	mathml_nemeth/mover_06.test		\
 	mathml_nemeth/mover_07.test		\
 	mathml_nemeth/mover_08.test		\
-	mathml_nemeth/mover_09.test		\
-	mathml_nemeth/mover_10.test		\
-	mathml_nemeth/mover_11.test		\
-	mathml_nemeth/mover_12.test		\
 	mathml_nemeth/mover_13.test		\
 	mathml_nemeth/mover_14.test		\
 	mathml_nemeth/mover_15.test		\
@@ -332,7 +328,6 @@ XFAIL_TESTS +=					\
 	mathml_nemeth/munder_01.test		\
 	mathml_nemeth/munder_02.test		\
 	mathml_nemeth/munder_03.test		\
-	mathml_nemeth/munder_04.test		\
 	mathml_nemeth/munder_05.test		\
 	mathml_nemeth/munder_06.test		\
 	mathml_nemeth/munder_07.test		\


code:
Copied from Debian.

From: Konstantinos Margaritis <markos@debian.org>
Subject: use "adr" instead of "add" to make code ready for thumb2

--- ./imdct_l_arm.S.orig	2010-02-25 13:25:23.000000000 +0100
+++ ./imdct_l_arm.S	2010-02-25 13:27:26.000000000 +0100
@@ -468,7 +468,7 @@

     @----

-    add     r2, pc, #(imdct36_long_karray-.-8)  @ r2 = base address of Knn array (PIC safe ?)
+    adr     r2, imdct36_long_karray

 loop:


code:
Copied from Debian.

From: Dave Martin
Subject: "rsc" doesnt exist anymore in thumb2

diff --git a/fixed.h b/fixed.h
index 4b58abf..ba4bc26 100644
--- a/fixed.h
+++ b/fixed.h
@@ -275,12 +275,25 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
 	 : "+r" (lo), "+r" (hi)  \
 	 : "%r" (x), "r" (y))

+#ifdef __thumb__
+/* In Thumb-2, the RSB-immediate instruction is only allowed with a zero
+	operand.  If needed this code can also support Thumb-1
+	(simply append "s" to the end of the second two instructions). */
+#  define MAD_F_MLN(hi, lo)  \
+    asm ("rsbs        %0, %0, #0\n\t"  \
+	 "sbc   %1, %1, %1\n\t"  \
+	 "sub   %1, %1, %2"  \
+	 : "+&r" (lo), "=&r" (hi)  \
+	 : "r" (hi)  \
+	 : "cc")
+#else /* ! __thumb__ */
 #  define MAD_F_MLN(hi, lo)  \
     asm ("rsbs	%0, %2, #0\n\t"  \
 	 "rsc	%1, %3, #0"  \
-	 : "=r" (lo), "=r" (hi)  \
+	 : "=&r" (lo), "=r" (hi)  \
 	 : "0" (lo), "1" (hi)  \
 	 : "cc")
+#endif /* __thumb__ */

 #  define mad_f_scale64(hi, lo)  \
     ({ mad_fixed_t __result;  \


code:
Copied from Debian.

From: Kurt Roeckx <kurt@roeckx.be>
Date: Sun, 28 Jan 2018 19:26:36 +0100
Subject: Check the size before reading with mad_bit_read

There are various cases where it attemps to read past the end of the buffer
using mad_bit_read(). Most functions didn't even know the size of the buffer
they were reading from.

Index: libmad-0.15.1b/bit.c
===================================================================
--- libmad-0.15.1b.orig/bit.c
+++ libmad-0.15.1b/bit.c
@@ -138,6 +138,9 @@ unsigned long mad_bit_read(struct mad_bi
 {
   register unsigned long value;

+  if (len == 0)
+    return 0;
+
   if (bitptr->left == CHAR_BIT)
     bitptr->cache = *bitptr->byte;

Index: libmad-0.15.1b/frame.c
===================================================================
--- libmad-0.15.1b.orig/frame.c
+++ libmad-0.15.1b/frame.c
@@ -120,11 +120,18 @@ static
 int decode_header(struct mad_header *header, struct mad_stream *stream)
 {
   unsigned int index;
+  struct mad_bitptr bufend_ptr;

   header->flags        = 0;
   header->private_bits = 0;

+  mad_bit_init(&bufend_ptr, stream->bufend);
+
   /* header() */
+  if (mad_bit_length(&stream->ptr, &bufend_ptr) < 32) {
+    stream->error = MAD_ERROR_BUFLEN;
+    return -1;
+  }

   /* syncword */
   mad_bit_skip(&stream->ptr, 11);
@@ -225,8 +232,13 @@ int decode_header(struct mad_header *hea
   /* error_check() */

   /* crc_check */
-  if (header->flags & MAD_FLAG_PROTECTION)
+  if (header->flags & MAD_FLAG_PROTECTION) {
+    if (mad_bit_length(&stream->ptr, &bufend_ptr) < 16) {
+      stream->error = MAD_ERROR_BUFLEN;
+      return -1;
+    }
     header->crc_target = mad_bit_read(&stream->ptr, 16);
+  }

   return 0;
 }
@@ -338,7 +350,7 @@ int mad_header_decode(struct mad_header
       stream->error = MAD_ERROR_BUFLEN;
       goto fail;
     }
-    else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
+    else if ((end - ptr >= 2) && !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
       /* mark point where frame sync word was expected */
       stream->this_frame = ptr;
       stream->next_frame = ptr + 1;
@@ -361,6 +373,8 @@ int mad_header_decode(struct mad_header
     ptr = mad_bit_nextbyte(&stream->ptr);
   }

+  stream->error = MAD_ERROR_NONE;
+
   /* begin processing */
   stream->this_frame = ptr;
   stream->next_frame = ptr + 1;  /* possibly bogus sync word */
@@ -413,7 +427,7 @@ int mad_header_decode(struct mad_header
     /* check that a valid frame header follows this frame */

     ptr = stream->next_frame;
-    if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
+    if ((end - ptr >= 2) && !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
       ptr = stream->next_frame = stream->this_frame + 1;
       goto sync;
     }
Index: libmad-0.15.1b/layer12.c
===================================================================
--- libmad-0.15.1b.orig/layer12.c
+++ libmad-0.15.1b/layer12.c
@@ -72,10 +72,18 @@ mad_fixed_t const linear_table[14] = {
  * DESCRIPTION:	decode one requantized Layer I sample from a bitstream
  */
 static
-mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb)
+mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb, struct mad_stream *stream)
 {
   mad_fixed_t sample;
+  struct mad_bitptr frameend_ptr;

+  mad_bit_init(&frameend_ptr, stream->next_frame);
+
+  if (mad_bit_length(ptr, &frameend_ptr) < nb) {
+    stream->error = MAD_ERROR_LOSTSYNC;
+    stream->sync = 0;
+    return 0;
+  }
   sample = mad_bit_read(ptr, nb);

   /* invert most significant bit, extend sign, then scale to fixed format */
@@ -106,6 +114,10 @@ int mad_layer_I(struct mad_stream *strea
   struct mad_header *header = &frame->header;
   unsigned int nch, bound, ch, s, sb, nb;
   unsigned char allocation[2][32], scalefactor[2][32];
+  struct mad_bitptr bufend_ptr, frameend_ptr;
+
+  mad_bit_init(&bufend_ptr, stream->bufend);
+  mad_bit_init(&frameend_ptr, stream->next_frame);

   nch = MAD_NCHANNELS(header);

@@ -118,6 +130,11 @@ int mad_layer_I(struct mad_stream *strea
   /* check CRC word */

   if (header->flags & MAD_FLAG_PROTECTION) {
+    if (mad_bit_length(&stream->ptr, &bufend_ptr)
+		< 4 * (bound * nch + (32 - bound))) {
+      stream->error = MAD_ERROR_BADCRC;
+      return -1;
+    }
     header->crc_check =
       mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)),
 		  header->crc_check);
@@ -133,6 +150,11 @@ int mad_layer_I(struct mad_stream *strea

   for (sb = 0; sb < bound; ++sb) {
     for (ch = 0; ch < nch; ++ch) {
+      if (mad_bit_length(&stream->ptr, &frameend_ptr) < 4) {
+	stream->error = MAD_ERROR_LOSTSYNC;
+	stream->sync = 0;
+	return -1;
+      }
       nb = mad_bit_read(&stream->ptr, 4);

       if (nb == 15) {
@@ -145,6 +167,11 @@ int mad_layer_I(struct mad_stream *strea
   }

   for (sb = bound; sb < 32; ++sb) {
+    if (mad_bit_length(&stream->ptr, &frameend_ptr) < 4) {
+      stream->error = MAD_ERROR_LOSTSYNC;
+      stream->sync = 0;
+      return -1;
+    }
     nb = mad_bit_read(&stream->ptr, 4);

     if (nb == 15) {
@@ -161,6 +188,11 @@ int mad_layer_I(struct mad_stream *strea
   for (sb = 0; sb < 32; ++sb) {
     for (ch = 0; ch < nch; ++ch) {
       if (allocation[ch][sb]) {
+        if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) {
+	  stream->error = MAD_ERROR_LOSTSYNC;
+	  stream->sync = 0;
+	  return -1;
+	}
 	scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6);

 # if defined(OPT_STRICT)
@@ -185,8 +217,10 @@ int mad_layer_I(struct mad_stream *strea
       for (ch = 0; ch < nch; ++ch) {
 	nb = allocation[ch][sb];
 	frame->sbsample[ch][s][sb] = nb ?
-	  mad_f_mul(I_sample(&stream->ptr, nb),
+	  mad_f_mul(I_sample(&stream->ptr, nb, stream),
 		    sf_table[scalefactor[ch][sb]]) : 0;
+	if (stream->error != 0)
+	  return -1;
       }
     }

@@ -194,7 +228,14 @@ int mad_layer_I(struct mad_stream *strea
       if ((nb = allocation[0][sb])) {
 	mad_fixed_t sample;

-	sample = I_sample(&stream->ptr, nb);
+	if (mad_bit_length(&stream->ptr, &frameend_ptr) < nb) {
+	  stream->error = MAD_ERROR_LOSTSYNC;
+	  stream->sync = 0;
+          return -1;
+	}
+	sample = I_sample(&stream->ptr, nb, stream);
+        if (stream->error != 0)
+	  return -1;

 	for (ch = 0; ch < nch; ++ch) {
 	  frame->sbsample[ch][s][sb] =
@@ -280,13 +321,21 @@ struct quantclass {
 static
 void II_samples(struct mad_bitptr *ptr,
 		struct quantclass const *quantclass,
-		mad_fixed_t output[3])
+		mad_fixed_t output[3], struct mad_stream *stream)
 {
   unsigned int nb, s, sample[3];
+  struct mad_bitptr frameend_ptr;
+
+  mad_bit_init(&frameend_ptr, stream->next_frame);

   if ((nb = quantclass->group)) {
     unsigned int c, nlevels;

+    if (mad_bit_length(ptr, &frameend_ptr) < quantclass->bits) {
+      stream->error = MAD_ERROR_LOSTSYNC;
+      stream->sync = 0;
+      return;
+    }
     /* degrouping */
     c = mad_bit_read(ptr, quantclass->bits);
     nlevels = quantclass->nlevels;
@@ -299,8 +348,14 @@ void II_samples(struct mad_bitptr *ptr,
   else {
     nb = quantclass->bits;

-    for (s = 0; s < 3; ++s)
+    for (s = 0; s < 3; ++s) {
+      if (mad_bit_length(ptr, &frameend_ptr) < nb) {
+	stream->error = MAD_ERROR_LOSTSYNC;
+	stream->sync = 0;
+	return;
+      }
       sample[s] = mad_bit_read(ptr, nb);
+    }
   }

   for (s = 0; s < 3; ++s) {
@@ -336,6 +391,9 @@ int mad_layer_II(struct mad_stream *stre
   unsigned char const *offsets;
   unsigned char allocation[2][32], scfsi[2][32], scalefactor[2][32][3];
   mad_fixed_t samples[3];
+  struct mad_bitptr frameend_ptr;
+
+  mad_bit_init(&frameend_ptr, stream->next_frame);

   nch = MAD_NCHANNELS(header);

@@ -402,13 +460,24 @@ int mad_layer_II(struct mad_stream *stre
   for (sb = 0; sb < bound; ++sb) {
     nbal = bitalloc_table[offsets[sb]].nbal;

-    for (ch = 0; ch < nch; ++ch)
+    for (ch = 0; ch < nch; ++ch) {
+      if (mad_bit_length(&stream->ptr, &frameend_ptr) < nbal) {
+	stream->error = MAD_ERROR_LOSTSYNC;
+	stream->sync = 0;
+	return -1;
+      }
       allocation[ch][sb] = mad_bit_read(&stream->ptr, nbal);
+    }
   }

   for (sb = bound; sb < sblimit; ++sb) {
     nbal = bitalloc_table[offsets[sb]].nbal;

+    if (mad_bit_length(&stream->ptr, &frameend_ptr) < nbal) {
+      stream->error = MAD_ERROR_LOSTSYNC;
+      stream->sync = 0;
+      return -1;
+    }
     allocation[0][sb] =
     allocation[1][sb] = mad_bit_read(&stream->ptr, nbal);
   }
@@ -417,8 +486,14 @@ int mad_layer_II(struct mad_stream *stre

   for (sb = 0; sb < sblimit; ++sb) {
     for (ch = 0; ch < nch; ++ch) {
-      if (allocation[ch][sb])
+      if (allocation[ch][sb]) {
+	if (mad_bit_length(&stream->ptr, &frameend_ptr) < 2) {
+	  stream->error = MAD_ERROR_LOSTSYNC;
+	  stream->sync = 0;
+	  return -1;
+	}
 	scfsi[ch][sb] = mad_bit_read(&stream->ptr, 2);
+      }
     }
   }

@@ -441,6 +516,11 @@ int mad_layer_II(struct mad_stream *stre
   for (sb = 0; sb < sblimit; ++sb) {
     for (ch = 0; ch < nch; ++ch) {
       if (allocation[ch][sb]) {
+	if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) {
+	  stream->error = MAD_ERROR_LOSTSYNC;
+	  stream->sync = 0;
+	  return -1;
+	}
 	scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6);

 	switch (scfsi[ch][sb]) {
@@ -451,11 +531,21 @@ int mad_layer_II(struct mad_stream *stre
 	  break;

 	case 0:
+	  if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) {
+	    stream->error = MAD_ERROR_LOSTSYNC;
+	    stream->sync = 0;
+	    return -1;
+	  }
 	  scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6);
 	  /* fall through */

 	case 1:
 	case 3:
+	  if (mad_bit_length(&stream->ptr, &frameend_ptr) < 6) {
+	    stream->error = MAD_ERROR_LOSTSYNC;
+	    stream->sync = 0;
+	    return -1;
+	  }
 	  scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6);
 	}

@@ -487,7 +577,9 @@ int mad_layer_II(struct mad_stream *stre
 	if ((index = allocation[ch][sb])) {
 	  index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];

-	  II_samples(&stream->ptr, &qc_table[index], samples);
+	  II_samples(&stream->ptr, &qc_table[index], samples, stream);
+	  if (stream->error != 0)
+            return -1;

 	  for (s = 0; s < 3; ++s) {
 	    frame->sbsample[ch][3 * gr + s][sb] =
@@ -505,7 +597,9 @@ int mad_layer_II(struct mad_stream *stre
       if ((index = allocation[0][sb])) {
 	index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];

-	II_samples(&stream->ptr, &qc_table[index], samples);
+	II_samples(&stream->ptr, &qc_table[index], samples, stream);
+	if (stream->error != 0)
+          return -1;

 	for (ch = 0; ch < nch; ++ch) {
 	  for (s = 0; s < 3; ++s) {
Index: libmad-0.15.1b/layer3.c
===================================================================
--- libmad-0.15.1b.orig/layer3.c
+++ libmad-0.15.1b/layer3.c
@@ -598,7 +598,8 @@ enum mad_error III_sideinfo(struct mad_b
 static
 unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr,
 				  struct channel *channel,
-				  struct channel *gr1ch, int mode_extension)
+				  struct channel *gr1ch, int mode_extension,
+				  unsigned int bits_left, unsigned int *part2_length)
 {
   struct mad_bitptr start;
   unsigned int scalefac_compress, index, slen[4], part, n, i;
@@ -644,8 +645,12 @@ unsigned int III_scalefactors_lsf(struct

     n = 0;
     for (part = 0; part < 4; ++part) {
-      for (i = 0; i < nsfb[part]; ++i)
+      for (i = 0; i < nsfb[part]; ++i) {
+	if (bits_left < slen[part])
+	  return MAD_ERROR_BADSCFSI;
 	channel->scalefac[n++] = mad_bit_read(ptr, slen[part]);
+	bits_left -= slen[part];
+      }
     }

     while (n < 39)
@@ -690,7 +695,10 @@ unsigned int III_scalefactors_lsf(struct
       max = (1 << slen[part]) - 1;

       for (i = 0; i < nsfb[part]; ++i) {
+	if (bits_left < slen[part])
+	  return MAD_ERROR_BADSCFSI;
 	is_pos = mad_bit_read(ptr, slen[part]);
+	bits_left -= slen[part];

 	channel->scalefac[n] = is_pos;
 	gr1ch->scalefac[n++] = (is_pos == max);
@@ -703,7 +711,8 @@ unsigned int III_scalefactors_lsf(struct
     }
   }

-  return mad_bit_length(&start, ptr);
+  *part2_length = mad_bit_length(&start, ptr);
+  return MAD_ERROR_NONE;
 }

 /*
@@ -712,7 +721,8 @@ unsigned int III_scalefactors_lsf(struct
  */
 static
 unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel,
-			      struct channel const *gr0ch, unsigned int scfsi)
+			      struct channel const *gr0ch, unsigned int scfsi,
+			      unsigned int bits_left, unsigned int *part2_length)
 {
   struct mad_bitptr start;
   unsigned int slen1, slen2, sfbi;
@@ -728,12 +738,20 @@ unsigned int III_scalefactors(struct mad
     sfbi = 0;

     nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3;
-    while (nsfb--)
+    while (nsfb--) {
+      if (bits_left < slen1)
+	return MAD_ERROR_BADSCFSI;
       channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1);
+      bits_left -= slen1;
+    }

     nsfb = 6 * 3;
-    while (nsfb--)
+    while (nsfb--) {
+      if (bits_left < slen2)
+	return MAD_ERROR_BADSCFSI;
       channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2);
+      bits_left -= slen2;
+    }

     nsfb = 1 * 3;
     while (nsfb--)
@@ -745,8 +763,12 @@ unsigned int III_scalefactors(struct mad
 	channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
     }
     else {
-      for (sfbi = 0; sfbi < 6; ++sfbi)
+      for (sfbi = 0; sfbi < 6; ++sfbi) {
+	if (bits_left < slen1)
+	  return MAD_ERROR_BADSCFSI;
 	channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
+	bits_left -= slen1;
+      }
     }

     if (scfsi & 0x4) {
@@ -754,8 +776,12 @@ unsigned int III_scalefactors(struct mad
 	channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
     }
     else {
-      for (sfbi = 6; sfbi < 11; ++sfbi)
+      for (sfbi = 6; sfbi < 11; ++sfbi) {
+	if (bits_left < slen1)
+	  return MAD_ERROR_BADSCFSI;
 	channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
+	bits_left -= slen1;
+      }
     }

     if (scfsi & 0x2) {
@@ -763,8 +789,12 @@ unsigned int III_scalefactors(struct mad
 	channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
     }
     else {
-      for (sfbi = 11; sfbi < 16; ++sfbi)
+      for (sfbi = 11; sfbi < 16; ++sfbi) {
+	if (bits_left < slen2)
+	  return MAD_ERROR_BADSCFSI;
 	channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
+	bits_left -= slen2;
+      }
     }

     if (scfsi & 0x1) {
@@ -772,14 +802,19 @@ unsigned int III_scalefactors(struct mad
 	channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
     }
     else {
-      for (sfbi = 16; sfbi < 21; ++sfbi)
+      for (sfbi = 16; sfbi < 21; ++sfbi) {
+	if (bits_left < slen2)
+	  return MAD_ERROR_BADSCFSI;
 	channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
+	bits_left -= slen2;
+      }
     }

     channel->scalefac[21] = 0;
   }

-  return mad_bit_length(&start, ptr);
+  *part2_length = mad_bit_length(&start, ptr);
+  return MAD_ERROR_NONE;
 }

 /*
@@ -933,19 +968,17 @@ static
 enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576],
 			      struct channel *channel,
 			      unsigned char const *sfbwidth,
-			      unsigned int part2_length)
+			      signed int part3_length)
 {
   signed int exponents[39], exp;
   signed int const *expptr;
   struct mad_bitptr peek;
-  signed int bits_left, cachesz;
+  signed int bits_left, cachesz, fakebits;
   register mad_fixed_t *xrptr;
   mad_fixed_t const *sfbound;
   register unsigned long bitcache;

-  bits_left = (signed) channel->part2_3_length - (signed) part2_length;
-  if (bits_left < 0)
-    return MAD_ERROR_BADPART3LEN;
+  bits_left = part3_length;

   III_exponents(channel, sfbwidth, exponents);

@@ -956,8 +989,12 @@ enum mad_error III_huffdecode(struct mad
   cachesz  = mad_bit_bitsleft(&peek);
   cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7;

+  if (bits_left < cachesz) {
+    cachesz = bits_left;
+  }
   bitcache   = mad_bit_read(&peek, cachesz);
   bits_left -= cachesz;
+  fakebits = 0;

   xrptr = &xr[0];

@@ -986,7 +1023,7 @@ enum mad_error III_huffdecode(struct mad

     big_values = channel->big_values;

-    while (big_values-- && cachesz + bits_left > 0) {
+    while (big_values-- && cachesz + bits_left - fakebits > 0) {
       union huffpair const *pair;
       unsigned int clumpsz, value;
       register mad_fixed_t requantized;
@@ -1023,10 +1060,19 @@ enum mad_error III_huffdecode(struct mad
 	unsigned int bits;

 	bits       = ((32 - 1 - 21) + (21 - cachesz)) & ~7;
+	if (bits_left < bits) {
+	  bits = bits_left;
+	}
 	bitcache   = (bitcache << bits) | mad_bit_read(&peek, bits);
 	cachesz   += bits;
 	bits_left -= bits;
       }
+      if (cachesz < 21) {
+	unsigned int bits = 21 - cachesz;
+	bitcache <<= bits;
+	cachesz += bits;
+	fakebits += bits;
+      }

       /* hcod (0..19) */

@@ -1041,6 +1087,8 @@ enum mad_error III_huffdecode(struct mad
       }

       cachesz -= pair->value.hlen;
+      if (cachesz < fakebits)
+	return MAD_ERROR_BADHUFFDATA;

       if (linbits) {
 	/* x (0..14) */
@@ -1054,10 +1102,15 @@ enum mad_error III_huffdecode(struct mad

 	case 15:
 	  if (cachesz < linbits + 2) {
-	    bitcache   = (bitcache << 16) | mad_bit_read(&peek, 16);
-	    cachesz   += 16;
-	    bits_left -= 16;
+	    unsigned int bits = 16;
+	    if (bits_left < 16)
+	      bits = bits_left;
+	    bitcache   = (bitcache << bits) | mad_bit_read(&peek, bits);
+	    cachesz   += bits;
+	    bits_left -= bits;
 	  }
+	  if (cachesz - fakebits < linbits)
+	    return MAD_ERROR_BADHUFFDATA;

 	  value += MASK(bitcache, cachesz, linbits);
 	  cachesz -= linbits;
@@ -1074,6 +1127,8 @@ enum mad_error III_huffdecode(struct mad
 	  }

 	x_final:
+	  if (cachesz - fakebits < 1)
+	    return MAD_ERROR_BADHUFFDATA;
 	  xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
 	    -requantized : requantized;
 	}
@@ -1089,10 +1144,15 @@ enum mad_error III_huffdecode(struct mad

 	case 15:
 	  if (cachesz < linbits + 1) {
-	    bitcache   = (bitcache << 16) | mad_bit_read(&peek, 16);
-	    cachesz   += 16;
-	    bits_left -= 16;
+	    unsigned int bits = 16;
+	    if (bits_left < 16)
+	      bits = bits_left;
+	    bitcache   = (bitcache << bits) | mad_bit_read(&peek, bits);
+	    cachesz   += bits;
+	    bits_left -= bits;
 	  }
+	  if (cachesz - fakebits < linbits)
+	    return MAD_ERROR_BADHUFFDATA;

 	  value += MASK(bitcache, cachesz, linbits);
 	  cachesz -= linbits;
@@ -1109,6 +1169,8 @@ enum mad_error III_huffdecode(struct mad
 	  }

 	y_final:
+	  if (cachesz - fakebits < 1)
+	    return MAD_ERROR_BADHUFFDATA;
 	  xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
 	    -requantized : requantized;
 	}
@@ -1128,6 +1190,8 @@ enum mad_error III_huffdecode(struct mad
 	    requantized = reqcache[value] = III_requantize(value, exp);
 	  }

+	  if (cachesz - fakebits < 1)
+	    return MAD_ERROR_BADHUFFDATA;
 	  xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
 	    -requantized : requantized;
 	}
@@ -1146,6 +1210,8 @@ enum mad_error III_huffdecode(struct mad
 	    requantized = reqcache[value] = III_requantize(value, exp);
 	  }

+	  if (cachesz - fakebits < 1)
+	    return MAD_ERROR_BADHUFFDATA;
 	  xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
 	    -requantized : requantized;
 	}
@@ -1155,9 +1221,6 @@ enum mad_error III_huffdecode(struct mad
     }
   }

-  if (cachesz + bits_left < 0)
-    return MAD_ERROR_BADHUFFDATA;  /* big_values overrun */
-
   /* count1 */
   {
     union huffquad const *table;
@@ -1167,15 +1230,24 @@ enum mad_error III_huffdecode(struct mad

     requantized = III_requantize(1, exp);

-    while (cachesz + bits_left > 0 && xrptr <= &xr[572]) {
+    while (cachesz + bits_left - fakebits > 0 && xrptr <= &xr[572]) {
       union huffquad const *quad;

       /* hcod (1..6) */

       if (cachesz < 10) {
-	bitcache   = (bitcache << 16) | mad_bit_read(&peek, 16);
-	cachesz   += 16;
-	bits_left -= 16;
+	unsigned int bits = 16;
+	if (bits_left < 16)
+	  bits = bits_left;
+	bitcache   = (bitcache << bits) | mad_bit_read(&peek, bits);
+	cachesz   += bits;
+	bits_left -= bits;
+      }
+      if (cachesz < 10) {
+	unsigned int bits = 10 - cachesz;
+	bitcache <<= bits;
+	cachesz += bits;
+	fakebits += bits;
       }

       quad = &table[MASK(bitcache, cachesz, 4)];
@@ -1188,6 +1260,11 @@ enum mad_error III_huffdecode(struct mad
 		      MASK(bitcache, cachesz, quad->ptr.bits)];
       }

+      if (cachesz - fakebits < quad->value.hlen + quad->value.v
+        + quad->value.w + quad->value.x + quad->value.y)
+	/* We don't have enough bits to read one more entry, consider them
+	 * stuffing bits. */
+	break;
       cachesz -= quad->value.hlen;

       if (xrptr == sfbound) {
@@ -1236,22 +1313,8 @@ enum mad_error III_huffdecode(struct mad

       xrptr += 2;
     }
-
-    if (cachesz + bits_left < 0) {
-# if 0 && defined(DEBUG)
-      fprintf(stderr, "huffman count1 overrun (%d bits)\n",
-	      -(cachesz + bits_left));
-# endif
-
-      /* technically the bitstream is misformatted, but apparently
-	 some encoders are just a bit sloppy with stuffing bits */
-
-      xrptr -= 4;
-    }
   }

-  assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT);
-
 # if 0 && defined(DEBUG)
   if (bits_left < 0)
     fprintf(stderr, "read %d bits too many\n", -bits_left);
@@ -2348,10 +2411,11 @@ void III_freqinver(mad_fixed_t sample[18
  */
 static
 enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
-			  struct sideinfo *si, unsigned int nch)
+			  struct sideinfo *si, unsigned int nch, unsigned int md_len)
 {
   struct mad_header *header = &frame->header;
   unsigned int sfreqi, ngr, gr;
+  int bits_left = md_len * CHAR_BIT;

   {
     unsigned int sfreq;
@@ -2383,6 +2447,7 @@ enum mad_error III_decode(struct mad_bit
     for (ch = 0; ch < nch; ++ch) {
       struct channel *channel = &granule->ch[ch];
       unsigned int part2_length;
+      unsigned int part3_length;

       sfbwidth[ch] = sfbwidth_table[sfreqi].l;
       if (channel->block_type == 2) {
@@ -2391,18 +2456,30 @@ enum mad_error III_decode(struct mad_bit
       }

       if (header->flags & MAD_FLAG_LSF_EXT) {
-	part2_length = III_scalefactors_lsf(ptr, channel,
+	error = III_scalefactors_lsf(ptr, channel,
 					    ch == 0 ? 0 : &si->gr[1].ch[1],
-					    header->mode_extension);
+					    header->mode_extension, bits_left, &part2_length);
       }
       else {
-	part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
-					gr == 0 ? 0 : si->scfsi[ch]);
+	error = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
+					gr == 0 ? 0 : si->scfsi[ch], bits_left, &part2_length);
       }
+      if (error)
+        return error;
+
+      bits_left -= part2_length;

-      error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length);
+      if (part2_length > channel->part2_3_length)
+        return MAD_ERROR_BADPART3LEN;
+
+      part3_length = channel->part2_3_length - part2_length;
+      if (part3_length > bits_left)
+        return MAD_ERROR_BADPART3LEN;
+
+      error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part3_length);
       if (error)
 	return error;
+      bits_left -= part3_length;
     }

     /* joint stereo processing */
@@ -2519,11 +2596,13 @@ int mad_layer_III(struct mad_stream *str
   unsigned int nch, priv_bitlen, next_md_begin = 0;
   unsigned int si_len, data_bitlen, md_len;
   unsigned int frame_space, frame_used, frame_free;
-  struct mad_bitptr ptr;
+  struct mad_bitptr ptr, bufend_ptr;
   struct sideinfo si;
   enum mad_error error;
   int result = 0;

+  mad_bit_init(&bufend_ptr, stream->bufend);
+
   /* allocate Layer III dynamic structures */

   if (stream->main_data == 0) {
@@ -2587,14 +2666,15 @@ int mad_layer_III(struct mad_stream *str
     unsigned long header;

     mad_bit_init(&peek, stream->next_frame);
+    if (mad_bit_length(&peek, &bufend_ptr) >= 57) {
+      header = mad_bit_read(&peek, 32);
+      if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
+        if (!(header & 0x00010000L))  /* protection_bit */
+	  mad_bit_skip(&peek, 16);  /* crc_check */

-    header = mad_bit_read(&peek, 32);
-    if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
-      if (!(header & 0x00010000L))  /* protection_bit */
-	mad_bit_skip(&peek, 16);  /* crc_check */
-
-      next_md_begin =
-	mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
+        next_md_begin =
+	  mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
+      }
     }

     mad_bit_finish(&peek);
@@ -2653,7 +2733,7 @@ int mad_layer_III(struct mad_stream *str
   /* decode main_data */

   if (result == 0) {
-    error = III_decode(&ptr, frame, &si, nch);
+    error = III_decode(&ptr, frame, &si, nch, md_len);
     if (error) {
       stream->error = error;
       result = -1;


code:
Copied from Debian.

From: Kurt Roeckx <kurt@roeckx.be>
Date: Sun, 28 Jan 2018 15:44:08 +0100
Subject: Check the size of the main data

The main data to decode a frame can come from the current frame and part of the
previous frame, the so called bit reservoir. si.main_data_begin is the part of
the previous frame we need for this frame. frame_space is the amount of main
data that can be in this frame, and next_md_begin is the part of this frame that
is going to be used for the next frame.

The maximum amount of data from a previous frame that the format allows is 511
bytes. The maximum frame size for the defined bitrates is at MPEG 2.5 layer 2
at 320 kbit/s and 8 kHz sample rate which gives 72 * (320000 / 8000) + 1 = 2881.
So those defines are not large enough:
 # define MAD_BUFFER_GUARD      8
 # define MAD_BUFFER_MDLEN      (511 + 2048 + MAD_BUFFER_GUARD)

There is also support for a "free" bitrate which allows you to create any frame
size, which can be larger than the buffer.

Changing the defines is not an option since it's part of the ABI, so we check
that the main data fits in the bufer.

The previous frame data is stored in *stream->main_data and contains
stream->md_len bytes. If stream->md_len is larger than the data we
need from the previous frame (si.main_data_begin) it still wouldn't fit
in the buffer, so just keep the data that we need.

Index: libmad-0.15.1b/layer3.c
===================================================================
--- libmad-0.15.1b.orig/layer3.c
+++ libmad-0.15.1b/layer3.c
@@ -2608,6 +2608,11 @@ int mad_layer_III(struct mad_stream *str
     next_md_begin = 0;

   md_len = si.main_data_begin + frame_space - next_md_begin;
+  if (md_len + MAD_BUFFER_GUARD > MAD_BUFFER_MDLEN) {
+    stream->error = MAD_ERROR_LOSTSYNC;
+    stream->sync = 0;
+    return -1;
+  }

   frame_used = 0;

@@ -2625,8 +2630,11 @@ int mad_layer_III(struct mad_stream *str
       }
     }
     else {
-      mad_bit_init(&ptr,
-		   *stream->main_data + stream->md_len - si.main_data_begin);
+      memmove(stream->main_data,
+	*stream->main_data + stream->md_len - si.main_data_begin,
+	si.main_data_begin);
+      stream->md_len = si.main_data_begin;
+      mad_bit_init(&ptr, *stream->main_data);

       if (md_len > si.main_data_begin) {
 	assert(stream->md_len + md_len -


code:
Fix MIPS assembly code to work with newer GCC, where the "=h"
constraint is no longer supported.

--- libmad/fixed.h.orig	2004-02-16 21:02:03.000000000 -0500
+++ libmad/fixed.h	2011-10-29 18:47:21.000000000 -0400
@@ -304,8 +304,8 @@
  * significant bit depends on OPT_ACCURACY via mad_f_scale64().
  */
 #  define MAD_F_MLX(hi, lo, x, y)  \
-    asm ("mult	%2,%3"  \
-	 : "=l" (lo), "=h" (hi)  \
+    asm ("mult	%2,%3\n\tmfhi  %1"  \
+	 : "=l" (lo), "=r" (hi)  \
 	 : "%r" (x), "r" (y))

 # if defined(HAVE_MADD_ASM)


code:
Author: Tobias Geerinckx-Rice <me@tobias.gr>
Date: Wed 22 Jan 22:58:13 CET 2020
Subject: gnu: memcached: Fix build with GCC 7.

Taken verbating from this bug report:
<https://bugs.launchpad.net/libmemcached/+bug/1663985>.

diff -up ./clients/memflush.cc.old ./clients/memflush.cc
--- ./clients/memflush.cc.old	2017-02-12 10:12:59.615209225 +0100
+++ ./clients/memflush.cc	2017-02-12 10:13:39.998382783 +0100
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
 {
   options_parse(argc, argv);

-  if (opt_servers == false)
+  if (!opt_servers)
   {
     char *temp;

@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
       opt_servers= strdup(temp);
     }

-    if (opt_servers == false)
+    if (!opt_servers)
     {
       std::cerr << "No Servers provided" << std::endl;
       exit(EXIT_FAILURE);


code:
Avoid a type mismatch that shows up in C++11.
Taken from <https://bugs.debian.org/853560>.

--- a/src/rtphint.cpp	2012-05-20 16:11:53.000000000 -0600
+++ b/src/rtphint.cpp	2017-05-16 10:25:26.930705191 -0600
@@ -339,7 +339,7 @@
                 pSlash = strchr(pSlash, '/');
                 if (pSlash != NULL) {
                     pSlash++;
-                    if (pSlash != '\0') {
+                    if (*pSlash != '\0') {
                         length = (uint32_t)strlen(pRtpMap) - (pSlash - pRtpMap);
                         *ppEncodingParams = (char *)MP4Calloc(length + 1);
                         strncpy(*ppEncodingParams, pSlash, length);


code:
Set visibility of global symbols used in ARM specific assembly file to
internal.

Taken from Debian:
https://salsa.debian.org/multimedia-team/mpeg2dec/blob/master/debian/patches/60_arm-private-symbols.patch

--- mpeg2dec.orig/libmpeg2/motion_comp_arm_s.S
+++ mpeg2dec/libmpeg2/motion_comp_arm_s.S
@@ -23,7 +23,8 @@

 @ ----------------------------------------------------------------
 	.align
-	.global MC_put_o_16_arm
+	.global   MC_put_o_16_arm
+	.internal MC_put_o_16_arm
 MC_put_o_16_arm:
 	@@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height)
 	pld [r1]
@@ -83,7 +84,8 @@ MC_put_o_16_arm_align_jt:

 @ ----------------------------------------------------------------
 	.align
-	.global MC_put_o_8_arm
+	.global   MC_put_o_8_arm
+	.internal MC_put_o_8_arm
 MC_put_o_8_arm:
 	@@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height)
 	pld [r1]
@@ -152,7 +154,8 @@ MC_put_o_8_arm_align_jt:
 .endm

 	.align
-	.global MC_put_x_16_arm
+	.global   MC_put_x_16_arm
+	.internal MC_put_x_16_arm
 MC_put_x_16_arm:
 	@@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height)
 	pld [r1]
@@ -244,7 +247,8 @@ MC_put_x_16_arm_align_jt:

 @ ----------------------------------------------------------------
 	.align
-	.global MC_put_x_8_arm
+	.global   MC_put_x_8_arm
+	.internal MC_put_x_8_arm
 MC_put_x_8_arm:
 	@@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height)
 	pld [r1]


code:
Rewrite the public symbol check to verify the shared libraries, to check for
more things, and to avoid duplication; fixes make check on ARM

Taken from Debian:
https://salsa.debian.org/multimedia-team/mpeg2dec/blob/master/debian/patches/61_global-symbol-test.patch

--- mpeg2dec.orig/test/globals
+++ mpeg2dec/test/globals
@@ -1,4 +1,8 @@
 #!/bin/sh
+# TODO
+# - fix checking of .a libs; problem is that "nm -g --defined-only" lists
+#   internal symbols; this can be solved by using objdump, but it's probably
+#   good enough to just run the tests on the shared lib

 if test x"$srcdir" != x""; then
     builddir="."	# running from make check, but it does not define that
@@ -14,22 +18,30 @@ builddir=`cd $builddir;pwd`

 error=0

-bad_globals=`nm -g --defined-only $builddir/../libmpeg2/*.o |\
-    awk '{if ($3) print $3}' | grep -v '^_\?mpeg2_'`
-
-if test x"$bad_globals" != x""; then
-    echo BAD GLOBAL SYMBOLS:
-    for s in $bad_globals; do echo $s; done
+# check_bad_public_symbols <symbol prefix> <lib file> [<lib file>...]
+#
+# checks public symbols in shared libs:
+# - allow prefix_anything
+# - reject _prefixanything
+# - allow _anything
+# - reject anything else
+#
+# NB: skips missing files
+check_bad_public_symbols() {
+    symbols_prefix="$1"
+    shift
+    lib_files=`ls "$@" 2>/dev/null`
+    [ -z "$lib_files" ] && return
+    bad_globals=`nm -g --defined-only $lib_files |
+        awk '{if ($3) print $3}' |
+        sed -n "/^${symbols_prefix}_/ d; /^_${symbols_prefix}/ { p; d }; /^_/ d; p"`
+    [ -z "$bad_globals" ] && return
     error=1
-fi
-
-bad_globals=`nm -g --defined-only $builddir/../libmpeg2/convert/*.o |\
-    awk '{if ($3) print $3}' | grep -v '^_\?mpeg2convert_'`
+    echo BAD GLOBAL SYMBOLS in $lib_files:
+    echo "$bad_globals"
+}

-if test x"$bad_globals" != x""; then
-    echo BAD GLOBAL SYMBOLS:
-    for s in $bad_globals; do echo $s; done
-    error=1
-fi
+check_bad_public_symbols mpeg2 $builddir/../libmpeg2/.libs/libmpeg2.so
+check_bad_public_symbols mpeg2convert $builddir/../libmpeg2/convert/.libs/libmpeg2convert.so

 exit $error


code:
From 1b53767b988b339aac8b353327a1542b2a0c0610 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <andreas.sturmlechner@gmail.com>
Date: Sun, 15 Apr 2018 22:29:33 +0200
Subject: [PATCH] Fix build with Qt 5.11_beta3 (dropping qt5_use_modules)

---
 CMakeLists.txt       |  3 ---
 src/CMakeLists.txt   |  8 ++++++--
 tests/CMakeLists.txt | 12 +++++++++---
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb006d9..fa4b0cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,9 +34,6 @@ else()
     set( QT_DONT_USE_QTGUI TRUE )
     include( ${QT_USE_FILE} )

-    macro(qt5_use_modules)
-    endmacro()
-
     macro(qt_wrap_cpp)
         qt4_wrap_cpp(${ARGN})
     endmacro()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 802125b..253e81e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -79,9 +79,13 @@ QT_WRAP_CPP(LIBMYGPO_QT_MOC_SRC ${LIBMYGPO_QT_MOC_H} )

 add_library( ${MYGPO_QT_TARGET_NAME} SHARED ${LIBMYGPO_QT_SRC} ${LIBMYGPO_QT_MOC_SRC} )

-target_link_libraries( ${MYGPO_QT_TARGET_NAME} ${QJSON_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY}  )
 set_target_properties( ${MYGPO_QT_TARGET_NAME} PROPERTIES VERSION ${MYGPO_QT_VERSION} SOVERSION ${MYGPO_QT_SONAME} DEFINE_SYMBOL MYGPO_MAKEDLL)
-qt5_use_modules( ${MYGPO_QT_TARGET_NAME} Core Network )
+
+if( NOT BUILD_WITH_QT4 )
+    target_link_libraries( ${MYGPO_QT_TARGET_NAME} Qt5::Core Qt5::Network)
+else()
+    target_link_libraries( ${MYGPO_QT_TARGET_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QJSON_LIBRARIES})
+endif()

 install( TARGETS ${MYGPO_QT_TARGET_NAME} EXPORT ${MYGPO_QT_TARGET_NAME}Export DESTINATION ${LIB_INSTALL_DIR} )

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a3e3223..4f77158 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -11,11 +11,15 @@ include_directories( ${QJSON_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CU

 # UrlBuilder library
 add_library( UrlBuilder ${TESTOBJECTS_SRCDIR}/UrlBuilder.cpp ${TESTOBJECTS_SRCDIR}/Config.cpp )
-qt5_use_modules( UrlBuilder Core )
+if( NOT BUILD_WITH_QT4 )
+    target_link_libraries( UrlBuilder Qt5::Core )
+endif()
 # JSONCreator library
 QT_WRAP_CPP(LIBMYGPO_QT_MOC_SRC ${TESTOBJECTS_SRCDIR}/EpisodeAction.h ${TESTOBJECTS_SRCDIR}/EpisodeAction_p.h )
 add_library( JsonCreator ${TESTOBJECTS_SRCDIR}/JsonCreator.cpp ${TESTOBJECTS_SRCDIR}/EpisodeAction.cpp ${TESTOBJECTS_SRCDIR}/qjsonwrapper/Json.cpp ${LIBMYGPO_QT_MOC_SRC})
-qt5_use_modules( JsonCreator Core Network )
+if( NOT BUILD_WITH_QT4 )
+    target_link_libraries( JsonCreator Qt5::Core Qt5::Network )
+endif()

 set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )

@@ -25,7 +29,9 @@ macro(add_libmygpo_test _source)
     add_executable(${_name} ${_source} ${${_name}_MOC_SRC})
     target_link_libraries(${_name} ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTNETWORK_LIBRARY})
     add_test(${_name}-test ${EXECUTABLE_OUTPUT_PATH}/${_name})
-    qt5_use_modules(${_name} Network Test)
+    if( NOT BUILD_WITH_QT4 )
+        target_link_libraries(${_name} Qt5::Network Qt5::Test)
+    endif()
 endmacro(add_libmygpo_test)

 add_libmygpo_test( UrlBuilderTest.cpp )


code:
From 0d76d960727018bddf04c6cc89552af69aaa7e55 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <andreas.sturmlechner@gmail.com>
Date: Sun, 15 Apr 2018 22:20:34 +0200
Subject: [PATCH] Add missing Qt5Network, Qt5Test, make BUILD_WITH_QT4 more
 strict

---
 CMakeLists.txt | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a1f652..eb006d9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,25 +5,25 @@ project( libmygpo-qt )
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII" )

-option(BUILD_WITH_QT4 "Build libmygpo-qt with Qt4 no matter if Qt5 was found" OFF)
+option(BUILD_WITH_QT4 "Build libmygpo-qt with Qt4" OFF)

 if( NOT BUILD_WITH_QT4 )
-    find_package(Qt5Core QUIET)
-    if( Qt5Core_DIR )
-        set(MYGPO_QT_VERSION_SUFFIX 5)
-
-        macro(qt_wrap_cpp)
-            qt5_wrap_cpp(${ARGN})
-        endmacro()
+    if( MYGPO_BUILD_TESTS )
+        find_package(Qt5 REQUIRED COMPONENTS Core Network Test CONFIG)
+    else()
+        find_package(Qt5 REQUIRED COMPONENTS Core Network CONFIG)
     endif()
+    set(MYGPO_QT_VERSION_SUFFIX 5)
+
+    macro(qt_wrap_cpp)
+        qt5_wrap_cpp(${ARGN})
+    endmacro()

     # pkg-config names of QtCore and QtNetwork are Qt5Core and Qt5Network for
     # Qt5
     set(MYGPO_QT_MAJOR_VERSION "5")
     set(MYGPO_QT4_QJSON_DEP "")
-endif()
-
-if( NOT Qt5Core_DIR )
+else()
     message(STATUS "Could not find Qt5, searching for Qt4 instead...")
     message(STATUS "Qt4 Support is deprecated, building with Qt4 is no longer officially supported")
     if( MYGPO_BUILD_TESTS )


code:
Description: Fix FTBFS due to unexisting and useless include. (Closes: #637896)
Author: Regis Boudin <regis@debian.org>
Last-Update: 2011-10-03
Index: libofa-0.9.3/examples/protocol.cpp
===================================================================
--- libofa-0.9.3.orig/examples/protocol.cpp
+++ libofa-0.9.3/examples/protocol.cpp
@@ -13,7 +13,6 @@
 #include <map>
 #include <expat.h>
 #include <curl/curl.h>
-#include <curl/types.h>
 #include <curl/easy.h>

 using namespace std;


code:
Description: fix FTBFS with GCC 4.3. (Closes: #417355)
Author: Martin Michlmayr <tbm@cyrius.com>
Last-Update: 2007-04-02

Description: add a missing include. (Closes: #441557)
Author: Brian M. Carlson <sandals@crustytoothpaste.ath.cx>
Last-Update: 2007-12-29

Index: libofa-0.9.3/lib/signal_op.cpp
===================================================================
--- libofa-0.9.3.orig/lib/signal_op.cpp
+++ libofa-0.9.3/lib/signal_op.cpp
@@ -12,6 +12,7 @@
 // DATE CREATED: 1/12/06

+#include <cstdlib>
 #include <math.h>
 #include "signal_op.h"
 #include "AFLIB/aflibConverter.h"
Index: libofa-0.9.3/examples/example.cpp
===================================================================
--- libofa-0.9.3.orig/examples/example.cpp
+++ libofa-0.9.3/examples/example.cpp
@@ -8,6 +8,8 @@
 -------------------------------------------------------------------*/

 #include "protocol.h"
+#include <cctype>
+#include <string.h>

 AudioData* loadWaveFile(char *file);
 AudioData* loadDataUsingLAME(char *file);
Index: libofa-0.9.3/examples/protocol.cpp
===================================================================
--- libofa-0.9.3.orig/examples/protocol.cpp
+++ libofa-0.9.3/examples/protocol.cpp
@@ -8,6 +8,7 @@
 -------------------------------------------------------------------*/
 #include <stdio.h>
 #include <stdlib.h>
+#include <cstring>
 #include <string>
 #include <map>
 #include <expat.h>


code:
Description: ftbfs with GCC-4.7. (Closes: #667250)
Author: Matthias Klose <doko@debian.org>
Last-Update: 2012-04-17
Index: libofa-0.9.3/examples/uselame.cpp
===================================================================
--- libofa-0.9.3.orig/examples/uselame.cpp
+++ libofa-0.9.3/examples/uselame.cpp
@@ -11,6 +11,7 @@
 #include "windows.h"
 #else
 #include <sys/wait.h>
+#include <unistd.h>
 #endif

 AudioData *loadWaveFile(char *file);
Index: libofa-0.9.3/examples/wavefile.cpp
===================================================================
--- libofa-0.9.3.orig/examples/wavefile.cpp
+++ libofa-0.9.3/examples/wavefile.cpp
@@ -11,6 +11,7 @@
 #include "io.h"
 #endif
 #include <fcntl.h>
+#include <unistd.h>

 static bool readBytes(int fd, unsigned char *buf, int size) {
     int ct = 0;


code:
Initialize the context in 'test_auth_clear'.
Fixes the test suite on mips64el.

Patch by Mark H Weaver <mhw@netris.org>

--- libotr-4.1.1/tests/unit/test_auth.c.orig	2015-12-25 12:39:45.000000000 -0500
+++ libotr-4.1.1/tests/unit/test_auth.c	2016-03-17 18:53:10.169999706 -0400
@@ -67,6 +67,7 @@
 	OtrlAuthInfo *auth = &ctx.auth;

 	/* API call. */
+	otrl_auth_new(&ctx);
 	otrl_auth_clear(auth);

 	ok(auth->authstate == OTRL_AUTHSTATE_NONE &&