On 5/4/2017 4:27 PM, Carl Eugen Hoyos wrote:
Hi!

Attached patch is one possibility to fix the following warning with gcc 7:
libavutil/timecode.c: In function ‘av_timecode_make_string’:
libavutil/timecode.c:103:60: warning: ‘%02d’ directive output may be truncated
writing between 2 and 10 bytes into a region of size between 0 and 7
[-Wformat-truncation=]
     snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d",
                                                            ^~~~
libavutil/timecode.c:103:41: note: directive argument in the range [0,
2147483647]
     snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d",
                                         ^~~~~~~~~~~~~~~~~~~~~~~~
libavutil/timecode.c:103:5: note: ‘snprintf’ output between 12 and 32 bytes
into a destination of size 16
     snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              neg ? "-" : "",
              ~~~~~~~~~~~~~~~
              hh, mm, ss, drop ? ';' : ':', ff);
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Several similar warnings are printed, an alternative is to disable the
warning.

The warning seemed wrong on first sight but may actually be correct, we
accept invalid fps for timecode.

Regarding the change in your patch:

-#define AV_TIMECODE_STR_SIZE 16
+#define AV_TIMECODE_STR_SIZE 23

It seems like 23 characters wouldn't be sufficient based on the warning: "output between 12 and 32 bytes into a destination of size 16". I would guess that you would need at least 32 characters and perhaps one more (?) for the terminating null character to avoid that warning. Even if in practice, it will never use 32 characters, its not a big deal to have a little waste here. The buffer size should match the format specification. An alternative would be to use "%02hd" or "%02hhd", but doing so would require casts or using different types for hh, mm, etc.

Aaron Levinson
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to