Opened 10 years ago

Closed 10 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 Carl Eugen Hoyos 10 years ago.

Download all attachments as: .zip

Change History (20)

comment:1 by cyril, 10 years ago

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 by Carl Eugen Hoyos, 10 years ago

How can I trigger the exception?

comment:3 by cyril, 10 years ago

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 by Carl Eugen Hoyos, 10 years ago

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 by cyril, 10 years ago

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 by Carl Eugen Hoyos, 10 years ago

How does your specific work-around look like?

comment:7 by cyril, 10 years ago

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

comment:8 by cyril, 10 years ago

Resolution: wontfix
Status: newclosed

comment:9 by Carl Eugen Hoyos, 10 years ago

Resolution: wontfix
Status: closedreopened

I intend to work on this issue.

comment:10 by Carl Eugen Hoyos, 10 years ago

Summary: Badly formatted DEBUG log in mjpegdec.cMSVC uses %ld for size_t and ptrdiff_t

comment:11 by Carl Eugen Hoyos, 10 years ago

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

comment:12 by cyril, 10 years ago

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

comment:13 by Carl Eugen Hoyos, 10 years ago

I had just realized this, patch updated.

by Carl Eugen Hoyos, 10 years ago

Attachment: patchptrdiff.diff added

comment:14 by Carl Eugen Hoyos, 10 years ago

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

comment:15 by Carl Eugen Hoyos, 10 years ago

Summary: MSVC uses %ld for size_t and ptrdiff_tMSVC uses %Id for size_t and ptrdiff_t

comment:16 by Andrey, 10 years ago

Thanks for a fix!

in reply to:  16 comment:17 by Carl Eugen Hoyos, 10 years ago

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 by cyril, 10 years ago

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 by Carl Eugen Hoyos, 10 years ago

Keywords: msvc added
Resolution: fixed
Status: reopenedclosed

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

Note: See TracTickets for help on using tickets.