views:

97

answers:

1

Hi, (this was asked on ffmpeg-devel list, but counted way offtopic, so posting it here).

ffmpeg.c loads multiple .c's, that are using log.c's av_log -> av_log_default_callback function, that uses fputs;

void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
{
...
snprintf(line, sizeof(line), "[%s @ %p] ", (*parent)->item_name(parent), parent);
... call to colored_fputs

Screen output:

static void colored_fputs(int level, const char *str){

...
fputs(str, stderr);

// this causes sigsegv just by fopen()
FILE * xFile;
xFile = fopen('yarr', 'w');
//fputs(str, xFile);fclose(xFile); // compile me. BOOM!
av_free(xFile); // last idea that came, using local free() version to avoid re-creatio

Each time, when fopen is put into code, it gives a segmentation fault of unknown reason. Why this kind of thing may happen here? Maybe due to blocking main I/O?

What are general 'blockers' that should be investigated in such a situation? Pthreads (involved in code somewhere)?

+3  A: 

fopen takes strings as arguments, you're giving it char literals

 xFile = fopen('yarr', 'w');

Should be

xFile = fopen("yarr", "w");
if(xFile == NULL) {
  perror("fopen failed");
  return;
}

The compiler should have warned about this, so make sure you've turned warning flags on (remeber to read them and fix them)

nos
Thanks, it was so simple that almost forgot that :)
mhambra