[FFmpeg-devel] [PATCH] wtvdec: *_to_iso8601: Behave less surprising

Alexander Strasser eclipse7 at gmx.net
Sun Jul 1 02:55:57 CEST 2012


  Do not violate the (implicit) contract that is indicated by
the arguments of those functions. In other words if buf_size
is passed as zero do not try to write to the buffer's first
element.
---

   I did not check if it is actually possible at any current
invocation places for the size of the passed buffer to be
be zero. The places are also limited to that file as the
functions are declared to have file scope. I just thought it
litters up the codebase little by little to have surprising
code like that, so I thought it is better to clean it up now.

   I did test nothing more than compilation on my machine.

 libavformat/wtvdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 338eff8..d356dc3 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -375,7 +375,7 @@ static void filetime_to_iso8601(char *buf, int buf_size, int64_t value)
     struct tm *tm = gmtime(&t);
     if (tm)
         strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-    else
+    else if (buf_size >= 1)
         buf[0] = '\0';
 }
 
@@ -388,7 +388,7 @@ static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
     struct tm *tm = gmtime(&t);
     if (tm)
         strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-    else
+    else if (buf_size >= 1)
         buf[0] = '\0';
 }
 
-- 
1.7.10.2.552.gaa3bb87


More information about the ffmpeg-devel mailing list