--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: g++-5: exceptions thrown from callback with va_list not caugth on at least armhf and powerpc
- From: Gert Wollny <gw.fossdev@gmail.com>
- Date: Tue, 19 Jul 2016 18:59:34 +0200
- Message-id: <146894757416.31720.15593937050736422848.reportbug@rohan.bai-gerddie.de>
Package: g++-5
Version: 5.4.0-6
Severity: important
Tags: upstream
Dear Maintainer,
in the attached program the exception is not caught on armhf and powerpc.
The compilation command line is
g++ test_tiff_throw.cc -o test-tiff-throw -ltiff
I've tested the compilers:
powerpc:
g++ (Debian 5.4.0-6) 5.4.0 20160609
g++-6 (Debian 6.1.1-9) 6.1.1 20160705
armhf:
g++ (Ubuntu/Linaro 5.3.1-14ubuntu2.1) 5.3.1 20160413
and optimization levels -O0, -O1, and -O2.
In each case the program aborts with
terminate called after throwing an instance of 'std::runtime_error'
what(): should_not_exists.tif: No such file or directory
Aborted
The code works as expected on amd64 with:
g++ (Debian 5.4.0-6) 5.4.0 20160609
g++ (Gentoo 5.4.0 p1.0, pie-0.6.5) 5.4.0
and i386:
g++ (Debian 5.4.0-6) 5.4.0 20160609
In this case the program prints:
"error: should_not_exists.tif: No such file or directory"
I was not able to create a simpler test case. Specifically:
Normally throw-catch works fine, i.e. the exception is caught even when using a
callback funtion that makes use of the va_list based constructs, but everything
resides in the same translation unit. The only way I can get this error
reproducible is by using libtiff that internally uses the va_* constructs to
forwards the error function to the user supplied function.
Tested libtiff5-dev:
4.0.6-2 (powerpc, amd64)
4.0.6-1 (armhf, i386)
Best regards,
Gert
-- System Information:
Debian Release: stretch/sid
APT prefers unstable-debug
APT policy: (500, 'unstable-debug'), (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 4.6.0-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages g++-5 depends on:
ii gcc-5 5.4.0-6
ii gcc-5-base 5.4.0-6
ii libc6 2.23-1
ii libgmp10 2:6.1.1+dfsg-1
ii libisl15 0.17.1-1
ii libmpc3 1.0.3-1
ii libmpfr4 3.1.4-2
ii libstdc++-5-dev 5.4.0-6
ii zlib1g 1:1.2.8.dfsg-2+b1
g++-5 recommends no packages.
Versions of packages g++-5 suggests:
pn g++-5-multilib <none>
pn gcc-5-doc <none>
pn libstdc++6-5-dbg <none>
-- no debconf information
#include <tiffio.h>
#include <exception>
#include <iostream>
typedef TIFF * PTIFF;
void MyErrorHandler(const char *module, const char *fmt, va_list ap)
{
char buf[16384];
vsnprintf(buf,16384, fmt, ap);
throw std::runtime_error(buf);
}
struct CErrorHandlerReplacer {
CErrorHandlerReplacer():
m_old_handler(TIFFSetErrorHandler(MyErrorHandler))
{
}
~CErrorHandlerReplacer() {
TIFFSetErrorHandler(m_old_handler);
}
private:
TIFFErrorHandler m_old_handler;
};
struct CTiffFile {
CTiffFile(const char *name, const char *flags):
handle(TIFFOpen(name, flags))
{
}
~CTiffFile()
{
if (handle)
TIFFClose(handle);
}
operator PTIFF() {
return handle;
}
private:
TIFF *handle;
};
int main(int argc, char **args)
{
CErrorHandlerReplacer error_replace;
try {
CTiffFile tif("should_not_exists.tif", "r");
if (tif) {
std::cerr << "File 'should_not_exists.tif' existed\n";
}
}catch (const std::runtime_error& x) {
std::cerr << "error: " << x.what() << "\n";
}
return 0;
}
--- End Message ---