[vlc-commits] [Git][videolan/vlc][master] 8 commits: alsa: use ARRAY_SIZE

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Nov 28 04:03:15 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
43905527 by Tristan Matthews at 2025-11-28T03:39:27+00:00
alsa: use ARRAY_SIZE

- - - - -
5cba57f9 by Tristan Matthews at 2025-11-28T03:39:27+00:00
bdagraph: use ARRAY_SIZE

- - - - -
785c8e6b by Tristan Matthews at 2025-11-28T03:39:27+00:00
access: dtv: use ARRAY_SIZE

- - - - -
ad337f2b by Tristan Matthews at 2025-11-28T03:39:27+00:00
access: http: use ARRAY_SIZE

- - - - -
81755d0b by Tristan Matthews at 2025-11-28T03:39:27+00:00
access: pipewire: use ARRAY_SIZE

- - - - -
c74d6e60 by Tristan Matthews at 2025-11-28T03:39:27+00:00
pulse: use ARRAY_SIZE

- - - - -
506fddb6 by Tristan Matthews at 2025-11-28T03:39:27+00:00
srt: use ARRAY_SIZE

- - - - -
75c26b9f by Tristan Matthews at 2025-11-28T03:39:27+00:00
access/v4l2: use ARRAY_SIZE

- - - - -


13 changed files:

- modules/access/alsa.c
- modules/access/dtv/bdagraph.cpp
- modules/access/dtv/linux.c
- modules/access/http/file_test.c
- modules/access/http/h2frame.c
- modules/access/http/h2frame_test.c
- modules/access/http/hpack.c
- modules/access/pipewire.c
- modules/access/pulse.c
- modules/access/srt_common.c
- modules/access/v4l2/controls.c
- modules/access/v4l2/v4l2.c
- modules/access/v4l2/video.c


Changes:

=====================================
modules/access/alsa.c
=====================================
@@ -397,7 +397,7 @@ static int Open (vlc_object_t *obj)
     }
 
     snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
-    for (size_t i = 0; i < sizeof (choices) / sizeof (choices[0]); i++)
+    for (size_t i = 0; i < ARRAY_SIZE(choices); i++)
         if (snd_pcm_hw_params_test_format (pcm, hw, choices[i]) == 0)
         {
             val = snd_pcm_hw_params_set_format (pcm, hw, choices[i]);
@@ -417,7 +417,7 @@ static int Open (vlc_object_t *obj)
         goto error;
     }
 
-    assert ((size_t)format < (sizeof (formats) / sizeof (formats[0])));
+    assert ((size_t)format < ARRAY_SIZE(formats));
     es_format_Init (&fmt, AUDIO_ES, formats[format]);
     fmt.audio.i_format = fmt.i_codec;
 
@@ -436,7 +436,7 @@ static int Open (vlc_object_t *obj)
         goto error;
     }
     assert (param > 0);
-    assert (param < (sizeof (channel_maps) / sizeof (channel_maps[0])));
+    assert (param < ARRAY_SIZE(channel_maps));
     fmt.audio.i_channels = param;
     fmt.audio.i_physical_channels = channel_maps[param - 1];
 


=====================================
modules/access/dtv/bdagraph.cpp
=====================================
@@ -3281,7 +3281,7 @@ HRESULT BDAGraph::Register()
         return hr;
     }
 
-    size_t len = sizeof(pwsz_graph_name) / sizeof(pwsz_graph_name[0]);
+    const size_t len = ARRAY_SIZE(pwsz_graph_name);
     _snwprintf( pwsz_graph_name, len - 1, L"VLC BDA Graph %08p Pid %08x",
         p_filter_graph, ::GetCurrentProcessId() );
     pwsz_graph_name[len-1] = 0;


=====================================
modules/access/dtv/linux.c
=====================================
@@ -114,7 +114,7 @@ static int dvb_parse_modulation (const char *str, int def)
         { "QAM",     QAM_AUTO },
         { "QPSK",   QPSK      },
     };
-    return dvb_parse_str (str, mods, sizeof (mods) / sizeof (*mods), def);
+    return dvb_parse_str (str, mods, ARRAY_SIZE(mods), def);
 }
 
 static int dvb_parse_fec (uint32_t fec)
@@ -136,8 +136,7 @@ static int dvb_parse_fec (uint32_t fec)
         { VLC_FEC(9,10), FEC_9_10 },
         { VLC_FEC_AUTO,  FEC_AUTO },
     };
-    return dvb_parse_int (fec, rates, sizeof (rates) / sizeof (*rates),
-                          FEC_AUTO);
+    return dvb_parse_int (fec, rates, ARRAY_SIZE(rates), FEC_AUTO);
 }
 
 
@@ -526,7 +525,7 @@ unsigned dvb_enum_systems (dvb_device_t *d)
     {
         unsigned sys = prop[1].u.buffer.data[i];
 
-        if (sys >= (sizeof (systab) / sizeof (systab[0])) || !systab[sys])
+        if (sys >= ARRAY_SIZE(systab) || !systab[sys])
         {
             msg_Warn (d->obj, "unknown delivery system %u", sys);
             continue;
@@ -782,7 +781,7 @@ int dvb_set_sec (dvb_device_t *d, uint64_t freq_Hz, char pol,
         };
         uint_fast16_t mHz = freq / 1000;
 
-        for (size_t i = 0; i < sizeof (tab) / sizeof (tab[0]); i++)
+        for (size_t i = 0; i < ARRAY_SIZE(tab); i++)
              if (mHz >= tab[i].min && mHz <= tab[i].max)
              {
                  lowf = tab[i].low * 1000;
@@ -982,8 +981,7 @@ static int dvb_parse_transmit_mode (int i)
         { 32, TRANSMISSION_MODE_32K  },
 #endif
     };
-    return dvb_parse_int (i, tab, sizeof (tab) / sizeof (*tab),
-                          TRANSMISSION_MODE_AUTO);
+    return dvb_parse_int (i, tab, ARRAY_SIZE(tab), TRANSMISSION_MODE_AUTO);
 }
 
 static int dvb_parse_guard (uint32_t guard)
@@ -1000,8 +998,7 @@ static int dvb_parse_guard (uint32_t guard)
 #endif
         { VLC_GUARD_AUTO,    GUARD_INTERVAL_AUTO },
     };
-    return dvb_parse_int (guard, tab, sizeof (tab) / sizeof (*tab),
-                          GUARD_INTERVAL_AUTO);
+    return dvb_parse_int (guard, tab, ARRAY_SIZE(tab), GUARD_INTERVAL_AUTO);
 }
 
 static int dvb_parse_hierarchy (int i)
@@ -1013,8 +1010,7 @@ static int dvb_parse_hierarchy (int i)
         { HIERARCHY_2,     2 },
         { HIERARCHY_4,     4 },
     };
-    return dvb_parse_int (i, tab, sizeof (tab) / sizeof (*tab),
-                          HIERARCHY_AUTO);
+    return dvb_parse_int (i, tab, ARRAY_SIZE(tab), HIERARCHY_AUTO);
 }
 
 int dvb_set_dvbt (dvb_device_t *d, uint32_t freq, const char *modstr,


=====================================
modules/access/http/file_test.c
=====================================
@@ -307,7 +307,7 @@ static struct vlc_http_msg *stream_read_headers(struct vlc_http_stream *s)
     }
 
     memmove(replies, replies + 1, sizeof (replies) - sizeof (replies[0]));
-    replies[(sizeof (replies) / sizeof (replies[0])) - 1] = NULL;
+    replies[ARRAY_SIZE(replies) - 1] = NULL;
 
     return m;
 }


=====================================
modules/access/http/h2frame.c
=====================================
@@ -117,7 +117,7 @@ static const char *vlc_h2_type_name(uint_fast8_t type)
         [VLC_H2_FRAME_CONTINUATION]  = "CONTINUATION",
     };
 
-    if (type >= (sizeof (names) / sizeof (names[0])) || names[type][0] == '\0')
+    if (type >= ARRAY_SIZE(names) || names[type][0] == '\0')
         return "<unknown>";
     return names[type];
 }
@@ -326,7 +326,7 @@ const char *vlc_h2_setting_name(uint_fast16_t id)
         [VLC_H2_SETTING_MAX_HEADER_LIST_SIZE]   = "Header list size",
     };
 
-    if (id >= sizeof (names) / sizeof (names[0]) || names[id][0] == '\0')
+    if (id >= ARRAY_SIZE(names) || names[id][0] == '\0')
         id = 0;
     return names[id];
 }
@@ -397,7 +397,7 @@ const char *vlc_h2_strerror(uint_fast32_t code)
         [VLC_H2_HTTP_1_1_REQUIRED]   = "Required HTTP/1.1",
     };
 
-    if (code >= sizeof (names) / sizeof (names[0]) || names[code][0] == '\0')
+    if (code >= ARRAY_SIZE(names) || names[code][0] == '\0')
         return "Unknown error";
     return names[code];
 }
@@ -975,8 +975,7 @@ static int vlc_h2_parse_generic(struct vlc_h2_parser *p,
 
     assert(p->headers.sid == 0);
 
-    if (type < sizeof (vlc_h2_parsers) / sizeof (vlc_h2_parsers[0])
-     && vlc_h2_parsers[type] != NULL)
+    if (type < ARRAY_SIZE(vlc_h2_parsers) && vlc_h2_parsers[type] != NULL)
         func = vlc_h2_parsers[type];
 
     return func(p, f, len, id);


=====================================
modules/access/http/h2frame_test.c
=====================================
@@ -155,7 +155,7 @@ static const char *const resp_hdrv[][2] = {
     { "set-cookie",       "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; "
                           "version=1" },
 };
-static const unsigned resp_hdrc = sizeof (resp_hdrv) / sizeof (resp_hdrv[0]);
+static const unsigned resp_hdrc = ARRAY_SIZE(resp_hdrv);
 
 static unsigned stream_header_tables;
 


=====================================
modules/access/http/hpack.c
=====================================
@@ -34,6 +34,7 @@
 #include <stdint.h>
 #include <string.h>
 
+#include "vlc_common.h"
 #include "hpack.h"
 
 /** Static Table header names */
@@ -334,10 +335,10 @@ static char *hpack_lookup_name(const struct hpack_decoder *dec,
     }
 
     idx--;
-    if (idx < sizeof (hpack_names) / sizeof (hpack_names[0]))
+    if (idx < ARRAY_SIZE(hpack_names))
         return strdup(hpack_names[idx]);
 
-    idx -= sizeof (hpack_names) / sizeof (hpack_names[0]);
+    idx -= ARRAY_SIZE(hpack_names);
     if (idx < dec->entries)
     {
         const char *entry = dec->table[dec->entries - (idx + 1)];
@@ -358,12 +359,12 @@ static char *hpack_lookup_value(const struct hpack_decoder *dec,
     }
 
     idx--;
-    if (idx < sizeof (hpack_values) / sizeof (hpack_values[0]))
+    if (idx < ARRAY_SIZE(hpack_values))
         return strdup(hpack_values[idx]);
-    if (idx < sizeof (hpack_names) / sizeof (hpack_names[0]))
+    if (idx < ARRAY_SIZE(hpack_names))
         return strdup("");
 
-    idx -= sizeof (hpack_names) / sizeof (hpack_names[0]);
+    idx -= ARRAY_SIZE(hpack_names);
     if (idx < dec->entries)
     {
         const char *entry = dec->table[dec->entries - (idx + 1)];


=====================================
modules/access/pipewire.c
=====================================
@@ -158,7 +158,7 @@ static int initialize_audio_format(struct vlc_pw_stream *s, es_format_t *fmt, vl
     {
         uint16_t vlc_chan = 0;
         uint32_t pos = s->audio_format.info.raw.position[i];
-        if (pos < sizeof (vlc_chans) / sizeof (vlc_chans[0]))
+        if (pos < ARRAY_SIZE(vlc_chans))
             vlc_chan = vlc_chans[pos];
 
         if (vlc_chan == 0)


=====================================
modules/access/pulse.c
=====================================
@@ -329,7 +329,7 @@ static int Open(vlc_object_t *obj)
 
     /* The ES should be initialized before stream_read_cb(), but how? */
     const struct pa_sample_spec *pss = pa_stream_get_sample_spec(s);
-    if ((unsigned)pss->format >= sizeof (fourccs) / sizeof (fourccs[0])) {
+    if ((unsigned)pss->format >= ARRAY_SIZE(fourccs)) {
         msg_Err(obj, "unknown PulseAudio sample format %u",
                 (unsigned)pss->format);
         goto error;


=====================================
modules/access/srt_common.c
=====================================
@@ -112,7 +112,7 @@ bool srt_parse_url(char* url, srt_params_t* params)
     query = find( url, '?' );
     if (query) {
         num_params = srt_url_parse_query( query, "&", local_params,
-                sizeof(local_params) / sizeof(struct parsed_param) );
+                ARRAY_SIZE(local_params));
         if (num_params > 0) {
             rc = true;
             for (i = 0; i < num_params; ++i) {


=====================================
modules/access/v4l2/controls.c
=====================================
@@ -335,7 +335,7 @@ static vlc_v4l2_ctrl_t *ControlCreate (int fd,
 
     /* Search for a well-known control */
     const vlc_v4l2_ctrl_name_t *known;
-    known = bsearch (&query->id, controls, sizeof (controls) / sizeof (*known),
+    known = bsearch (&query->id, controls, ARRAY_SIZE(controls),
                      sizeof (*known), cidcmp);
     if (known != NULL)
         strcpy (ctrl->name, known->name);
@@ -719,7 +719,7 @@ vlc_v4l2_ctrl_t *ControlsInit (vlc_object_t *obj, int fd)
     while (v4l2_ioctl (fd, VIDIOC_QUERYCTRL, &query) >= 0)
     {
         ctrl_type_cb handler = NULL;
-        if (query.type < (sizeof (handlers) / sizeof (handlers[0])))
+        if (query.type < ARRAY_SIZE(handlers))
             handler = handlers[query.type];
         if (handler == NULL)
             handler = ControlAddUnknown;


=====================================
modules/access/v4l2/v4l2.c
=====================================
@@ -503,13 +503,11 @@ v4l2_std_id var_InheritStandard (vlc_object_t *obj, const char *varname)
     if (name == NULL)
         return V4L2_STD_UNKNOWN;
 
-    const size_t n = sizeof (standards_vlc) / sizeof (*standards_vlc);
+    const size_t n = ARRAY_SIZE(standards_vlc);
 
-    static_assert (sizeof (standards_vlc) / sizeof (*standards_vlc)
-                         == sizeof (standards_v4l2) / sizeof (*standards_v4l2),
+    static_assert (ARRAY_SIZE(standards_vlc) == ARRAY_SIZE(standards_v4l2),
                    "Inconsistent standards tables");
-    static_assert (sizeof (standards_vlc) / sizeof (*standards_vlc)
-                         == sizeof (standards_user) / sizeof (*standards_user),
+    static_assert (ARRAY_SIZE(standards_vlc) == ARRAY_SIZE(standards_user),
                    "Inconsistent standards tables");
 
     for (size_t i = 0; i < n; i++)


=====================================
modules/access/v4l2/video.c
=====================================
@@ -673,7 +673,7 @@ static const vlc_v4l2_fmt_t v4l2_fmts[] =
 
 static const vlc_v4l2_fmt_t *vlc_from_v4l2_fourcc (uint32_t fourcc)
 {
-     for (size_t i = 0; i < sizeof (v4l2_fmts) / sizeof (v4l2_fmts[0]); i++)
+     for (size_t i = 0; i < ARRAY_SIZE(v4l2_fmts); i++)
          if (v4l2_fmts[i].v4l2 == fourcc)
              return v4l2_fmts + i;
      return NULL;
@@ -686,7 +686,7 @@ static size_t vlc_v4l2_fmt_rank (const vlc_v4l2_fmt_t *fmt)
 
     ptrdiff_t d = fmt - v4l2_fmts;
     assert (d >= 0);
-    assert (d < (ptrdiff_t)(sizeof (v4l2_fmts) / sizeof (v4l2_fmts[0])));
+    assert (d < (ptrdiff_t)(ARRAY_SIZE(v4l2_fmts)));
     return d;
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ff3b751173f3eb9687661318b932433c005bcaf8...75c26b9fde45a72562bbf6747f40b26bef946419

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ff3b751173f3eb9687661318b932433c005bcaf8...75c26b9fde45a72562bbf6747f40b26bef946419
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list