Am Do., 9. Juli 2026 um 10:51 Uhr schrieb Peter Maydell <[email protected]>: > > On Thu, 9 Jul 2026 at 09:47, Alexander Mikhalitsyn > <[email protected]> wrote: > > > > From: Alexander Mikhalitsyn <[email protected]> > > > > Let's use GPtrArray to build a list of blocker features and then > > g_strjoinv() to build a final comma-delimited string. > > > > While previous approach was technically correct, it is fragile > > (because we need to take care of static buffer size choice) and > > Coverity dislikes it too. > > > > Note, that we use g_ptr_array_new() to allocate array which means > > that GDestroyNotify callback is not set, so we can pass pointers to > > a static memory like g_ptr_array_add(..., (gpointer) "SR-IOV") without > > any problems as there won't be any attempt to free that memory. > > > > Resolves: Coverity CID 1663673 > > Suggested-by: Peter Maydell <[email protected]> > > Signed-off-by: Alexander Mikhalitsyn <[email protected]> > > --- > > hw/nvme/ctrl.c | 41 +++++++++++++++++------------------------ > > 1 file changed, 17 insertions(+), 24 deletions(-) > > > > diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c > > index a67e1598891..95a586d82a9 100644 > > --- a/hw/nvme/ctrl.c > > +++ b/hw/nvme/ctrl.c > > @@ -9352,22 +9352,11 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice > > *pci_dev) > > } > > } > > > > -#define BLOCKER_FEATURES_MAX_LEN 256 > > - > > -static inline void nvme_add_blocker_feature(char *blocker_features, > > - const char *feature) > > -{ > > - if (strlen(blocker_features) > 0) { > > - g_strlcat(blocker_features, ", ", BLOCKER_FEATURES_MAX_LEN); > > - } > > - g_strlcat(blocker_features, feature, BLOCKER_FEATURES_MAX_LEN); > > -} > > - > > static bool nvme_set_migration_blockers(NvmeCtrl *n, PCIDevice *pci_dev, > > Error **errp) > > { > > uint64_t unsupported_cap, cap = ldq_le_p(&n->bar.cap); > > - char blocker_features[BLOCKER_FEATURES_MAX_LEN] = ""; > > + g_autoptr(GPtrArray) blocker_features = g_ptr_array_new(); > > bool adm_cmd_security_checked = false; > > bool cmd_io_mgmt_checked = false; > > bool cmd_zone_checked = false; > > @@ -9416,15 +9405,15 @@ static bool nvme_set_migration_blockers(NvmeCtrl > > *n, PCIDevice *pci_dev, > > } > > > > if (namespaces_num > 1) { > > - nvme_add_blocker_feature(blocker_features, > > - "Namespace Attachment"); > > + g_ptr_array_add(blocker_features, > > + (gpointer) "Namespace > > Attachment"); >
Hi Peter, > Is the cast here because we're dropping the const property of the > literal string? yep. Compiler output without this cast: >../hw/nvme/ctrl.c:9418:42: error: passing 'const char[21]' to parameter of >type 'gpointer' (aka 'void *') discards qualifiers >[-Werror,-Wincompatible-pointer-types-discards-qualifiers] >9418 | "Namespace Attachment"); Kind regards, Alex > > thanks > -- PMM
