From 7714e7ca44f9d46ce7557e5103e4b76d0a9a257b Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 14 May 2020 16:20:51 +0200 Subject: [PATCH] Using union to pass a size_t when the uri is of type uri_id --- inc/lektor/uri.h | 6 +++++- src/commands.c | 8 ++------ src/database/queue.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/inc/lektor/uri.h b/inc/lektor/uri.h index b9ab5087..c24f82ef 100644 --- a/inc/lektor/uri.h +++ b/inc/lektor/uri.h @@ -17,7 +17,11 @@ enum lkt_uri_type { struct lkt_uri { enum lkt_uri_type type; - void *value; + union { + void *value; + size_t id; + }; + bool _allocated; }; diff --git a/src/commands.c b/src/commands.c index 824fe657..5a84e9a1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -268,13 +268,11 @@ command_addid(volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ { UNUSED(win); RETURN_UNLESS(args, "Invalid argument", false); - long id; char *endptr = NULL, err = 0; struct lkt_uri uri = { .type = uri_id }; *watch_mask_ptr |= MPD_IDLE_PLAYLIST; - STRTOL(id, args[0], endptr, err); + STRTOL(uri.id, args[0], endptr, err); RETURN_IF(err, "STRTOL failed", false); - uri.value = (void *) (size_t) id; return database_queue_add_uri(db, &uri, 1); } @@ -283,13 +281,11 @@ command_multiaddid(volatile sqlite3 *db, struct lkt_win *win, char *args[LKT_MES { UNUSED(win); RETURN_UNLESS(args, "Invalid argument", false); - long id; char *endptr = NULL, err = 0; struct lkt_uri uri = { .type = uri_id }; *watch_mask_ptr |= MPD_IDLE_PLAYLIST; - STRTOL(id, args[0], endptr, err); + STRTOL(uri.id, args[0], endptr, err); RETURN_IF(err, "STRTOL failed", false); - uri.value = &id; return database_queue_add_uri(db, &uri, 1); /* UNUSED(win); diff --git a/src/database/queue.c b/src/database/queue.c index 7d476cfa..ca045524 100644 --- a/src/database/queue.c +++ b/src/database/queue.c @@ -266,7 +266,7 @@ database_queue_add_uri(volatile sqlite3 *db, struct lkt_uri *uri, int priority) return queue_add_with_col_like_str(db, LKT_DATABASE_KARA_ALL, uri->value, priority); case uri_id: - return database_queue_add_id(db, *(size_t *) uri->value, priority); + return database_queue_add_id(db, uri->id, priority); case uri_type: return queue_add_with_col_like_str(db, LKT_DATABASE_NAME_KTYPE, uri->value, priority); -- GitLab