diff mbox series

[FFmpeg-devel,3/9] lavd/v4l2: reduce variable scope

Message ID 20211125150500.25040-3-anton@khirnov.net
State Accepted
Commit b532ca3d2f1f1caab71c0aab979949882b695198
Headers show
Series [FFmpeg-devel,1/9] lavd/jack: increase buffer size for snprintf()
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Anton Khirnov Nov. 25, 2021, 3:04 p.m. UTC
device and cap are local to the loop iteration, there is no need for
them to retain their values. Especially for device it may be dangerous,
since it points to av_malloc'ed data.
---
 libavdevice/v4l2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andreas Rheinhardt Nov. 26, 2021, 5:50 p.m. UTC | #1
Anton Khirnov:
> device and cap are local to the loop iteration, there is no need for
> them to retain their values. Especially for device it may be dangerous,
> since it points to av_malloc'ed data.
> ---
>  libavdevice/v4l2.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
> index 777867db86..c286b31c69 100644
> --- a/libavdevice/v4l2.c
> +++ b/libavdevice/v4l2.c
> @@ -1019,8 +1019,6 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
>      struct video_data *s = ctx->priv_data;
>      DIR *dir;
>      struct dirent *entry;
> -    AVDeviceInfo *device = NULL;
> -    struct v4l2_capability cap;
>      int ret = 0;
>  
>      if (!device_list)
> @@ -1033,6 +1031,8 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
>          return ret;
>      }
>      while ((entry = readdir(dir))) {
> +        AVDeviceInfo *device = NULL;
> +        struct v4l2_capability cap;
>          int fd = -1;
>          char device_name[256];
>  
> 

LGTM.

- Andreas
diff mbox series

Patch

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 777867db86..c286b31c69 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -1019,8 +1019,6 @@  static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
     struct video_data *s = ctx->priv_data;
     DIR *dir;
     struct dirent *entry;
-    AVDeviceInfo *device = NULL;
-    struct v4l2_capability cap;
     int ret = 0;
 
     if (!device_list)
@@ -1033,6 +1031,8 @@  static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
         return ret;
     }
     while ((entry = readdir(dir))) {
+        AVDeviceInfo *device = NULL;
+        struct v4l2_capability cap;
         int fd = -1;
         char device_name[256];