Opened 5 years ago

Closed 4 years ago

#3472 closed defect (fixed)

MSVC uses %Id for size_t and ptrdiff_t

Reported by: cyril Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: msvc
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: A badly formatted log in mjpegdec.c just make ffmpeg throw an exception when log is at DEBUG level.

In mjpegdec.c at line 1861:
av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n",

%td should be replaced by %d

Attachments (1)

patchptrdiff.diff (15.7 KB) - added by cehoyos 5 years ago.

Download all attachments as: .zip

Change History (20)

comment:1 Changed 5 years ago by cyril

I didn't know that %td was one of the new formatting rules of printf().
I don't have the rights to close a track, please feel free to do so.

comment:2 Changed 5 years ago by cehoyos

How can I trigger the exception?

comment:3 Changed 5 years ago by cyril

You'll have to develop a Visual C++ 2010 application using FFmpeg dlls, which is redirecting avlog() streams to _vsntprintf_s().
As VC++ 2010 doesn't support %td, _vsntprintf_s just raise an invalid formatter exception.

comment:4 Changed 5 years ago by cehoyos

Do I understand correctly that this is not reproducible with newer versions of Visual Studio? A "fix" is possible but this is not a regression and if newer MS compilers do not show this behaviour, I wonder if a possible change is worth the effort.

comment:5 Changed 5 years ago by cyril

I've just checked MSDN and VC++ 2013 still have the same issue: %td and %ti aren't supported at all.
Anyway as I stated in "comment 1", I don't think it's worth the effort as it can easily be fixed with a workaround, so feel free to close this track.

comment:6 Changed 5 years ago by cehoyos

How does your specific work-around look like?

comment:7 Changed 5 years ago by cyril

Quite simple: I replace all those %td by %ld before passing them to VC++ printf functions

comment:8 Changed 5 years ago by cyril

  • Resolution set to wontfix
  • Status changed from new to closed

comment:9 Changed 5 years ago by cehoyos

  • Resolution wontfix deleted
  • Status changed from closed to reopened

I intend to work on this issue.

comment:10 Changed 5 years ago by cehoyos

  • Summary changed from Badly formatted DEBUG log in mjpegdec.c to MSVC uses %ld for size_t and ptrdiff_t

comment:11 Changed 5 years ago by cehoyos

Could you test if attached patch fixes the issue for you?

comment:12 Changed 5 years ago by cyril

I'll test it later but if it works it won't be enough as %ti is also used in FFmpeg.

comment:13 Changed 5 years ago by cehoyos

I had just realized this, patch updated.

Changed 5 years ago by cehoyos

comment:14 Changed 5 years ago by cehoyos

Updated once more for size_t and correct specifier according to msdn.

comment:15 Changed 5 years ago by cehoyos

  • Summary changed from MSVC uses %ld for size_t and ptrdiff_t to MSVC uses %Id for size_t and ptrdiff_t

comment:16 follow-up: Changed 5 years ago by nikolaynnov

Thanks for a fix!

comment:17 in reply to: ↑ 16 Changed 5 years ago by cehoyos

Replying to nikolaynnov:

Thanks for a fix!

Sorry if I misunderstand: Did you test the patch and it fixes an issue for you?
I unfortunately cannot test...

comment:18 Changed 5 years ago by cyril

Sorry for the late reply.
I've just tested your patch on a few problematic files and now it's working fine with MSVC, the debug output doesn't cause any crash anymore.

comment:19 Changed 4 years ago by cehoyos

  • Keywords msvc added
  • Resolution set to fixed
  • Status changed from reopened to closed

Should be fixed in ced0d6c1 - thank you for the report and the testing!

Note: See TracTickets for help on using tickets.