Skip to content

Commit

Permalink
replace memset with talloc_zero
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Dec 27, 2023
1 parent 5ead199 commit b8ea9b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.13)

project(mpv-plugin)
project(mpv-menu-plugin C)
set(CMAKE_C_STANDARD 11)

include(FindPkgConfig)
pkg_search_module(MPV REQUIRED mpv>=0.37.0)
Expand Down
9 changes: 3 additions & 6 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ static wchar_t *format_title(void *talloc_ctx, bstr name, bstr key) {
static int append_menu(HMENU hmenu, UINT fMask, UINT fType, UINT fState,
wchar_t *title, HMENU submenu, void *data) {
static UINT id = WM_USER + 100;
MENUITEMINFOW mii;
memset(&mii, 0, sizeof(mii));
MENUITEMINFOW mii = {0};

mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | fMask;
Expand Down Expand Up @@ -289,8 +288,7 @@ static bool update_audio_device_menu(plugin_ctx *ctx, dyn_entry *item) {
}

static void dyn_menu_init(void *talloc_ctx) {
dyn_menus = talloc_ptrtype(talloc_ctx, dyn_menus);
memset(dyn_menus, 0, sizeof(*dyn_menus));
dyn_menus = talloc_zero(talloc_ctx, dyn_list);
}

static void dyn_menu_update(plugin_ctx *ctx) {
Expand Down Expand Up @@ -407,8 +405,7 @@ void show_menu(plugin_ctx *ctx, POINT *pt) {
}

void handle_menu(plugin_ctx *ctx, int id) {
MENUITEMINFOW mii;
memset(&mii, 0, sizeof(mii));
MENUITEMINFOW mii = {0};
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_DATA;
if (!GetMenuItemInfoW(ctx->hmenu, id, FALSE, &mii)) return;
Expand Down
11 changes: 3 additions & 8 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,9 @@ static void handle_client_message(mpv_event *event) {
}

static plugin_ctx *create_plugin_ctx() {
plugin_ctx *ctx = talloc_ptrtype(NULL, ctx);
memset(ctx, 0, sizeof(*ctx));

ctx->conf = talloc_ptrtype(ctx, ctx->conf);
memset(ctx->conf, 0, sizeof(*ctx->conf));
ctx->state = talloc_ptrtype(ctx, ctx->state);
memset(ctx->state, 0, sizeof(*ctx->state));

plugin_ctx *ctx = talloc_zero(NULL, plugin_ctx);
ctx->conf = talloc_zero(ctx, plugin_config);
ctx->state = talloc_zero(ctx, mp_state);
return ctx;
}

Expand Down
24 changes: 8 additions & 16 deletions src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

static void update_track_list(mp_state *state, mpv_node *node) {
if (state->track_list != NULL) talloc_free(state->track_list);
state->track_list = talloc_ptrtype(state, state->track_list);
memset(state->track_list, 0, sizeof(*state->track_list));
state->track_list = talloc_zero(state, mp_track_list);
mp_track_list *list = state->track_list;

for (int i = 0; i < node->u.list->num; i++) {
mpv_node track = node->u.list->values[i];

mp_track_item item;
memset(&item, 0, sizeof(item));
mp_track_item item = {0};

for (int j = 0; j < track.u.list->num; j++) {
char *key = track.u.list->keys[j];
Expand Down Expand Up @@ -50,15 +48,13 @@ static void update_track_list(mp_state *state, mpv_node *node) {

static void update_chapter_list(mp_state *state, mpv_node *node) {
if (state->chapter_list != NULL) talloc_free(state->chapter_list);
state->chapter_list = talloc_ptrtype(state, state->chapter_list);
memset(state->chapter_list, 0, sizeof(*state->chapter_list));
state->chapter_list = talloc_zero(state, mp_chapter_list);
mp_chapter_list *list = state->chapter_list;

for (int i = 0; i < node->u.list->num; i++) {
mpv_node chapter = node->u.list->values[i];

mp_chapter_item item;
memset(&item, 0, sizeof(item));
mp_chapter_item item = {0};

for (int j = 0; j < chapter.u.list->num; j++) {
char *key = chapter.u.list->keys[j];
Expand All @@ -80,15 +76,13 @@ static void update_chapter_list(mp_state *state, mpv_node *node) {

static void update_edition_list(mp_state *state, mpv_node *node) {
if (state->edition_list != NULL) talloc_free(state->edition_list);
state->edition_list = talloc_ptrtype(state, state->edition_list);
memset(state->edition_list, 0, sizeof(*state->edition_list));
state->edition_list = talloc_zero(state, mp_edition_list);
mp_edition_list *list = state->edition_list;

for (int i = 0; i < node->u.list->num; i++) {
mpv_node edition = node->u.list->values[i];

mp_edition_item item;
memset(&item, 0, sizeof(item));
mp_edition_item item = {0};

for (int j = 0; j < edition.u.list->num; j++) {
char *key = edition.u.list->keys[j];
Expand All @@ -110,15 +104,13 @@ static void update_edition_list(mp_state *state, mpv_node *node) {

static void update_audio_device_list(mp_state *state, mpv_node *node) {
if (state->audio_device_list != NULL) talloc_free(state->audio_device_list);
state->audio_device_list = talloc_ptrtype(state, state->audio_device_list);
memset(state->audio_device_list, 0, sizeof(*state->audio_device_list));
state->audio_device_list = talloc_zero(state, mp_audio_device_list);
mp_audio_device_list *list = state->audio_device_list;

for (int i = 0; i < node->u.list->num; i++) {
mpv_node device = node->u.list->values[i];

mp_audio_device item;
memset(&item, 0, sizeof(item));
mp_audio_device item = {0};

for (int j = 0; j < device.u.list->num; j++) {
char *key = device.u.list->keys[j];
Expand Down

0 comments on commit b8ea9b7

Please sign in to comment.