[FFmpeg-cvslog] pktdumper: Use sizeof(variable) instead of the direct buffer length

Martin Storsjö git at videolan.org
Fri Aug 31 13:39:11 CEST 2012


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Thu Aug 30 23:08:06 2012 +0300| [372de27df78b85976991bfe321a43b62b8505276] | committer: Martin Storsjö

pktdumper: Use sizeof(variable) instead of the direct buffer length

Also change the snprintf size to use the full buffer, since
snprintf always null-terminates the buffer.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=372de27df78b85976991bfe321a43b62b8505276
---

 tools/pktdumper.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/pktdumper.c b/tools/pktdumper.c
index 9243c93..fffeeeb 100644
--- a/tools/pktdumper.c
+++ b/tools/pktdumper.c
@@ -70,16 +70,16 @@ int main(int argc, char **argv)
         return usage(1);
     if (argc > 2)
         maxpkts = atoi(argv[2]);
-    strncpy(fntemplate, argv[1], PATH_MAX - 1);
+    strncpy(fntemplate, argv[1], sizeof(fntemplate) - 1);
     if (strrchr(argv[1], '/'))
-        strncpy(fntemplate, strrchr(argv[1], '/') + 1, PATH_MAX - 1);
+        strncpy(fntemplate, strrchr(argv[1], '/') + 1, sizeof(fntemplate) - 1);
     if (strrchr(fntemplate, '.'))
         *strrchr(fntemplate, '.') = '\0';
     if (strchr(fntemplate, '%')) {
         fprintf(stderr, "can't use filenames containing '%%'\n");
         return usage(1);
     }
-    if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX - 1) {
+    if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= sizeof(fntemplate) - 1) {
         fprintf(stderr, "filename too long\n");
         return usage(1);
     }
@@ -105,7 +105,7 @@ int main(int argc, char **argv)
 
     while ((err = av_read_frame(fctx, &pkt)) >= 0) {
         int fd;
-        snprintf(pktfilename, PATH_MAX - 1, fntemplate, pktnum,
+        snprintf(pktfilename, sizeof(pktfilename), fntemplate, pktnum,
                  pkt.stream_index, pkt.pts, pkt.size,
                  (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
         printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size,



More information about the ffmpeg-cvslog mailing list