diff mbox series

[FFmpeg-devel] lavf, lavfi: Remove uses of sizeof(char)

Message ID CAB0OVGrh-GB4UfiqxbYaRAHVNmQgcuc0BTE3+tp-ZYFKa8SXAw@mail.gmail.com
State Accepted
Headers show
Series [FFmpeg-devel] lavf, lavfi: Remove uses of sizeof(char) | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Carl Eugen Hoyos April 3, 2020, 11:31 p.m. UTC
Hi!

Attached patch removes uses of sizeof(char) from libavfilter and libavformat.

Please comment, Carl Eugen

Comments

Andreas Rheinhardt April 4, 2020, 4:40 a.m. UTC | #1
Carl Eugen Hoyos:
> Hi!
> 
> Attached patch removes uses of sizeof(char) from libavfilter and libavformat.
> 
> Please comment, Carl Eugen
> 
The commit message is misleading: Actually C is based around
sizeof(char) = 1. From the semantics of the sizeof operator: "When
applied to an operand that has type char, unsigned char, or signed char,
(or a qualified version thereof) the result is 1." (C90, 6.3.3.4; C99,
6.5.3.4).

- Andreas
Carl Eugen Hoyos April 4, 2020, 9:22 p.m. UTC | #2
Am Sa., 4. Apr. 2020 um 06:40 Uhr schrieb Andreas Rheinhardt
<andreas.rheinhardt@gmail.com>:
>
> Carl Eugen Hoyos:
> > Hi!
> >
> > Attached patch removes uses of sizeof(char) from libavfilter and libavformat.
> >
> > Please comment, Carl Eugen
> >
> The commit message is misleading: Actually C is based around
> sizeof(char) = 1. From the semantics of the sizeof operator: "When
> applied to an operand that has type char, unsigned char, or signed char,
> (or a qualified version thereof) the result is 1." (C90, 6.3.3.4; C99,
> 6.5.3.4).

Pushed with an improved commit message.

Carl Eugen
diff mbox series

Patch

From eb8c99ab8b714b8699adfb252723ee66f00cd00f Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Sat, 4 Apr 2020 01:30:14 +0200
Subject: [PATCH] lavf, lavfi: Remove uses of sizeof(char).

FFmpeg relies on sizeof(char) == 1.
---
 libavfilter/dnn/dnn_backend_tf.c | 2 +-
 libavfilter/vf_deshake.c         | 4 ++--
 libavformat/webmdashenc.c        | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c
index a921667424..9ceca5cea0 100644
--- a/libavfilter/dnn/dnn_backend_tf.c
+++ b/libavfilter/dnn/dnn_backend_tf.c
@@ -95,7 +95,7 @@  static TF_Tensor *allocate_input_tensor(const DNNData *input)
         break;
     case DNN_UINT8:
         dt = TF_UINT8;
-        size = sizeof(char);
+        size = 1;
         break;
     default:
         av_assert0(!"should not reach here");
diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
index b516ea2d59..28a541b94a 100644
--- a/libavfilter/vf_deshake.c
+++ b/libavfilter/vf_deshake.c
@@ -354,7 +354,7 @@  static av_cold int init(AVFilterContext *ctx)
     if (deshake->filename)
         deshake->fp = fopen(deshake->filename, "w");
     if (deshake->fp)
-        fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", sizeof(char), 104, deshake->fp);
+        fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", 1, 104, deshake->fp);
 
     // Quadword align left edge of box for MMX code, adjust width if necessary
     // to keep right margin
@@ -485,7 +485,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
     // Write statistics to file
     if (deshake->fp) {
         snprintf(tmp, 256, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n", orig.vec.x, deshake->avg.vec.x, t.vec.x, orig.vec.y, deshake->avg.vec.y, t.vec.y, orig.angle, deshake->avg.angle, t.angle, orig.zoom, deshake->avg.zoom, t.zoom);
-        fwrite(tmp, sizeof(char), strlen(tmp), deshake->fp);
+        fwrite(tmp, 1, strlen(tmp), deshake->fp);
     }
 
     // Turn relative current frame motion into absolute by adding it to the
diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index d05b265330..7847659c63 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -439,7 +439,7 @@  static int write_adaptation_set(AVFormatContext *s, int as_index)
 static int to_integer(char *p, int len)
 {
     int ret;
-    char *q = av_malloc(sizeof(char) * len);
+    char *q = av_malloc(len);
     if (!q)
         return AVERROR(ENOMEM);
     av_strlcpy(q, p, len);
-- 
2.24.1