Skip to content
  • Markus Armbruster's avatar
    1366244a
    9pfs: Use g_new() & friends where that makes obvious sense · 1366244a
    Markus Armbruster authored
    
    
    g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
    for two reasons.  One, it catches multiplication overflowing size_t.
    Two, it returns T * rather than void *, which lets the compiler catch
    more type errors.
    
    This commit only touches allocations with size arguments of the form
    sizeof(T).
    
    Initial patch created mechanically with:
    
        $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
    	     --macro-file scripts/cocci-macro-file.h FILES...
    
    This uncovers a typing error:
    
        ../hw/9pfs/9p.c: In function ‘qid_path_fullmap’:
        ../hw/9pfs/9p.c:855:13: error: assignment to ‘QpfEntry *’ from incompatible pointer type ‘QppEntry *’ [-Werror=incompatible-pointer-types]
          855 |         val = g_new0(QppEntry, 1);
    	  |             ^
    
    Harmless, because QppEntry is larger than QpfEntry.  Manually fixed to
    allocate a QpfEntry instead.
    
    Cc: Greg Kurz <groug@kaod.org>
    Cc: Christian Schoenebeck <qemu_oss@crudebyte.com>
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
    Reviewed-by: default avatarChristian Schoenebeck <qemu_oss@crudebyte.com>
    Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
    Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <20220315144156.1595462-3-armbru@redhat.com>
    1366244a
    9pfs: Use g_new() & friends where that makes obvious sense
    Markus Armbruster authored
    
    
    g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
    for two reasons.  One, it catches multiplication overflowing size_t.
    Two, it returns T * rather than void *, which lets the compiler catch
    more type errors.
    
    This commit only touches allocations with size arguments of the form
    sizeof(T).
    
    Initial patch created mechanically with:
    
        $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
    	     --macro-file scripts/cocci-macro-file.h FILES...
    
    This uncovers a typing error:
    
        ../hw/9pfs/9p.c: In function ‘qid_path_fullmap’:
        ../hw/9pfs/9p.c:855:13: error: assignment to ‘QpfEntry *’ from incompatible pointer type ‘QppEntry *’ [-Werror=incompatible-pointer-types]
          855 |         val = g_new0(QppEntry, 1);
    	  |             ^
    
    Harmless, because QppEntry is larger than QpfEntry.  Manually fixed to
    allocate a QpfEntry instead.
    
    Cc: Greg Kurz <groug@kaod.org>
    Cc: Christian Schoenebeck <qemu_oss@crudebyte.com>
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
    Reviewed-by: default avatarChristian Schoenebeck <qemu_oss@crudebyte.com>
    Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
    Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <20220315144156.1595462-3-armbru@redhat.com>
Loading