On 9/12/25 13:50, Stefan Weil via wrote:
This fixes a compiler error when higher warning levels are enabled:

../migration/postcopy-ram.c: In function ‘postcopy_temp_pages_setup’:
../migration/postcopy-ram.c:1483:50: error: ‘g_malloc0_n’ sizes specified with 
‘sizeof’ in the earlier argument and not in the later argument 
[-Werror=calloc-transposed-args]
  1483 |     mis->postcopy_tmp_pages = g_malloc0_n(sizeof(PostcopyTmpPage), 
channels);
       |                                                  ^~~~~~~~~~~~~~~
../migration/postcopy-ram.c:1483:50: note: earlier argument should specify 
number of elements, later size of each element

Avoid also a related int/unsigned mismatch by fixing the type of
two local variables.

Signed-off-by: Stefan Weil <[email protected]>
---
  migration/postcopy-ram.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 3f98dcb6fd..8bef0192aa 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -1467,7 +1467,8 @@ retry:
  static int postcopy_temp_pages_setup(MigrationIncomingState *mis)
  {
      PostcopyTmpPage *tmp_page;
-    int err, i, channels;
+    int err;
+    unsigned i, channels;
      void *temp_page;
if (migrate_postcopy_preempt()) {
@@ -1479,7 +1480,7 @@ static int 
postcopy_temp_pages_setup(MigrationIncomingState *mis)
      }
channels = mis->postcopy_channels;
-    mis->postcopy_tmp_pages = g_malloc0_n(sizeof(PostcopyTmpPage), channels);
+    mis->postcopy_tmp_pages = g_malloc0_n(channels, sizeof(PostcopyTmpPage));

I suppose we wanted to use:

    g_new0(PostcopyTmpPage, channels)

What is the benefit of g_malloc0_n() over g_new0()?

for (i = 0; i < channels; i++) {
          tmp_page = &mis->postcopy_tmp_pages[i];

Anyhow,

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


Reply via email to