[PATCH 0/2] Fix some coding issues

*** BLURB HERE *** Jiang Jiacheng (2): qemu: convert the flags type to unsigned long coding-style: Use the same style in the same structure src/locking/lock_daemon.c | 12 ++++++------ src/logging/log_daemon.c | 12 ++++++------ src/qemu/qemu_migration.c | 4 ++-- src/remote/remote_daemon.c | 14 +++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) -- 2.33.0

The flags type is unsigend long but passed as unsigend int when invoke 'qemuMigrationSrcNBDStorageCopy'. Modify it to prevent data truncation. Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com> --- src/qemu/qemu_migration.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index bba4e1dbf3..ba6c933885 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1077,7 +1077,7 @@ qemuMigrationSrcNBDStorageCopyOne(virDomainObj *vm, bool mirror_shallow, const char *tlsAlias, const char *tlsHostname, - unsigned int flags) + unsigned long flags) { qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); qemuBlockJobData *job = NULL; @@ -1142,7 +1142,7 @@ qemuMigrationSrcNBDStorageCopy(virQEMUDriver *driver, const char *tlsAlias, const char *tlsHostname, const char *nbdURI, - unsigned int flags) + unsigned long flags) { qemuDomainObjPrivate *priv = vm->privateData; int port; -- 2.33.0

On Sat, Nov 19, 2022 at 17:31:27 +0800, Jiang Jiacheng wrote:
The flags type is unsigend long but passed as unsigend int when invoke 'qemuMigrationSrcNBDStorageCopy'. Modify it to prevent data truncation.
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com> --- src/qemu/qemu_migration.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Actually the use of 'unsigned long flags' in the migration APIs is a historical mistake. While we can't remove that type from the function prototype, internally the code MUST use 32 bit at most as 'unsigned long' is not portable between 32 and 64 bit hosts.

Coding-style of members in the same structure should be unified. Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com> --- src/locking/lock_daemon.c | 12 ++++++------ src/logging/log_daemon.c | 12 ++++++------ src/remote/remote_daemon.c | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index c997d327c4..5eed6b7c26 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -809,14 +809,14 @@ int main(int argc, char **argv) { int rv; struct option opts[] = { - { "verbose", no_argument, &verbose, 'v'}, - { "daemon", no_argument, &godaemon, 'd'}, - { "config", required_argument, NULL, 'f'}, - { "timeout", required_argument, NULL, 't'}, - { "pid-file", required_argument, NULL, 'p'}, + { "verbose", no_argument, &verbose, 'v' }, + { "daemon", no_argument, &godaemon, 'd' }, + { "config", required_argument, NULL, 'f' }, + { "timeout", required_argument, NULL, 't' }, + { "pid-file", required_argument, NULL, 'p' }, { "version", no_argument, NULL, 'V' }, { "help", no_argument, NULL, 'h' }, - {0, 0, 0, 0} + { 0, 0, 0, 0 }, }; privileged = geteuid() == 0; diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 00fc4148fd..9b70ffad2f 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -613,14 +613,14 @@ int main(int argc, char **argv) { int rv; struct option opts[] = { - { "verbose", no_argument, &verbose, 'v'}, - { "daemon", no_argument, &godaemon, 'd'}, - { "config", required_argument, NULL, 'f'}, - { "timeout", required_argument, NULL, 't'}, - { "pid-file", required_argument, NULL, 'p'}, + { "verbose", no_argument, &verbose, 'v' }, + { "daemon", no_argument, &godaemon, 'd' }, + { "config", required_argument, NULL, 'f' }, + { "timeout", required_argument, NULL, 't' }, + { "pid-file", required_argument, NULL, 'p' }, { "version", no_argument, NULL, 'V' }, { "help", no_argument, NULL, 'h' }, - {0, 0, 0, 0} + { 0, 0, 0, 0 }, }; privileged = geteuid() == 0; diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index f369d09d35..dd9344168b 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -807,17 +807,17 @@ int main(int argc, char **argv) { mode_t old_umask; struct option opts[] = { - { "verbose", no_argument, &verbose, 'v'}, - { "daemon", no_argument, &godaemon, 'd'}, + { "verbose", no_argument, &verbose, 'v' }, + { "daemon", no_argument, &godaemon, 'd' }, #if defined(WITH_IP) && defined(LIBVIRTD) - { "listen", no_argument, &ipsock, 'l'}, + { "listen", no_argument, &ipsock, 'l' }, #endif /* !(WITH_IP && LIBVIRTD) */ - { "config", required_argument, NULL, 'f'}, - { "timeout", required_argument, NULL, 't'}, - { "pid-file", required_argument, NULL, 'p'}, + { "config", required_argument, NULL, 'f' }, + { "timeout", required_argument, NULL, 't' }, + { "pid-file", required_argument, NULL, 'p' }, { "version", no_argument, NULL, 'V' }, { "help", no_argument, NULL, 'h' }, - {0, 0, 0, 0} + { 0, 0, 0, 0 }, }; if (virGettextInitialize() < 0 || -- 2.33.0

On 11/19/22 10:31, Jiang Jiacheng wrote:
Coding-style of members in the same structure should be unified.
Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com> --- src/locking/lock_daemon.c | 12 ++++++------ src/logging/log_daemon.c | 12 ++++++------ src/remote/remote_daemon.c | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-)
After this, there are still some 'misaligned' options: libvirt.git $ git grep -A10 "struct option" Could you fix them all? Michal
participants (3)
-
Jiang Jiacheng
-
Michal Prívozník
-
Peter Krempa