joncampbell123 / composite-video-simulator

Code to process video to simulate analog composite video.
139 stars 17 forks source link

normalize_ts.cpp:217:49: error: taking address of temporary array #5

Open CTXz opened 6 years ago

CTXz commented 6 years ago

av_err2str makes use of C array constructs that break newer versions of G++.

See: https://ffmpeg.org/pipermail/libav-user/2013-January/003458.html

Error:

In file included from normalize_ts.cpp:37:0:
normalize_ts.cpp:217:49: error: taking address of temporary array
         fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
                                                 ^
Makefile:725: recipe for target 'normalize_ts-normalize_ts.o' failed
make[2]: *** [normalize_ts-normalize_ts.o] Error 1
make[2]: Leaving directory '/home/ctxz/dev/composite-video-simulator'
Makefile:745: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/ctxz/dev/composite-video-simulator'
Makefile:448: recipe for target 'all' failed
make: *** [all] Error 2

G++:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.2.0-8ubuntu3.2' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2)

To work this issue around, I've placed the following macros, as suggested by this mail from the Libav-user mailinglist, after line line 40:

#undef av_err2str
#define av_err2str(errnum) av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)

With av_err2str being overwritten, compilation succeeds.

sampleref commented 4 years ago

With g++ version 5.4.0 CPP 11

I tried as below,

av_always_inline char *av_err2str_inline(int errnum) { static char str[AV_ERROR_MAX_STRING_SIZE]; memset(str, 0, sizeof(str)); return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum); }

fprintf(stderr, "Could not open codec: %s\n", av_err2str_inline(ret));

As mentioned at http://libav-users.943685.n4.nabble.com/Libav-user-g-4-7-2-fails-to-compile-av-err2str-td4656417.html

vacing commented 4 years ago

I prefer @sampleref 's answer, to be specified, put the below in your header

// fix temporary array error in c++1x
#ifdef av_err2str
#undef av_err2str
av_always_inline char* av_err2str(int errnum)
{
    // static char str[AV_ERROR_MAX_STRING_SIZE];
    // thread_local may be better than static in multi-thread circumstance
    thread_local char str[AV_ERROR_MAX_STRING_SIZE]; 
    memset(str, 0, sizeof(str));
    return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
}
#endif

updated again:

#ifdef av_err2str
#undef av_err2str
#include <string>
av_always_inline std::string av_err2string(int errnum) {
    char str[AV_ERROR_MAX_STRING_SIZE];
    return av_make_error_string(str, AV_ERROR_MAX_STRING_SIZE, errnum);
}
#define av_err2str(err) av_err2string(err).c_str()
#endif  // av_err2str
sathyaprakashk commented 4 years ago

Followed blindly @vacing it worked perfectly

vacing commented 4 years ago

@sathyaprakashk updated my answer

asmwarrior commented 1 year ago

Hi, guys, thanks for the fix, as of today, I see that I still see such error when using G++ with the latest ffmpeg library. Thanks for your solutions!

RenaKunisaki commented 6 months ago

The same applies to av_ts2timestr:

#ifdef av_ts2timestr
#undef av_ts2timestr
#include <string>
av_always_inline std::string av_ts2timestring(int64_t ts, AVRational *tb) {
    char str[AV_TS_MAX_STRING_SIZE];
    return av_ts_make_time_string(str, ts, tb);
}
#define av_ts2timestr(ts, tb) av_ts2timestring((ts), (tb)).c_str()
#endif  // av_ts2timestr