3

Could anyone explain why the following crashes with an access violation at 0xFFFFFFFF at avformat_open_input?

std::string u8(const std::wstring& str)
{
    return boost::locale::conv::utf_to_utf<char>(str);
}

AVFormatContext* open_input(const std::wstring& filename)
{
    AVFormatContext* context = nullptr;
    avformat_open_input(&context, u8(filename).c_str(), nullptr, nullptr);
    avformat_find_stream_info(context, nullptr);
    return context;
}

while the following works:

AVFormatContext* open_input(const std::wstring& filename)
{
    auto u8filename = u8(filename);
    AVFormatContext* context = nullptr;
    avformat_open_input(&context, u8filename.c_str(), nullptr, nullptr);        
    avformat_find_stream_info(context, nullptr);
    return context;
}
ronag
  • 49,529
  • 25
  • 126
  • 221
  • Show us avformat_open_input definition. – Tomek Apr 12 '12 at 15:55
  • 1
    @Tomek: http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavformat/utils.c;h=2f926bb4e0784b031456fce7b477a7eebac8b440;hb=refs/heads/master#l583 – ronag Apr 12 '12 at 15:59
  • What does the implementation of `u8` look like? – David Heffernan Apr 12 '12 at 16:06
  • I think you also need to provide the compiler/boost version and maybe the generated assembly for two dummy calls that exhibit the problem (if possible). – pmr Apr 12 '12 at 16:15

1 Answers1

2

The result of u8(filename).c_str() should be usable until avformat_open_input returns. It's probably saving the pointer you give it and then using that during avformat_find_stream_info.

Post the docs for these avformat functions, or their implementations so we can see if it's actually doing that.


It doesn't look like avformat_open_input is doing anything wrong. Now I suspect that there's undefined behavior occurring somewhere earlier in the program. Try using a tool like valgrind or static analysis and see if that turns up anything.

bames53
  • 86,085
  • 15
  • 179
  • 244