diff mbox

[1/2] avoid asprintf (not available on mingw64)

Message ID 1344605205-28583-2-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Aug. 10, 2012, 1:26 p.m. UTC
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/msix.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

Comments

Markus Armbruster Aug. 10, 2012, 2:18 p.m. UTC | #1
Gerd Hoffmann <kraxel@redhat.com> writes:

> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/msix.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/hw/msix.c b/hw/msix.c
> index 800fc32..04345f2 100644
> --- a/hw/msix.c
> +++ b/hw/msix.c
> @@ -307,9 +307,8 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
>          return -EINVAL;
>      }
>  
> -    if (asprintf(&name, "%s-msix", dev->name) == -1) {
> -        return -ENOMEM;
> -    }
> +    name = g_malloc(sizeof(dev->name) + 5);
> +    snprintf(name, sizeof(dev->name) + 5, "%s-msix", dev->name);
>  
>      memory_region_init(&dev->msix_exclusive_bar, name, MSIX_EXCLUSIVE_BAR_SIZE);

What about g_strdup_printf()?
Blue Swirl Aug. 12, 2012, 9:54 a.m. UTC | #2
On Fri, Aug 10, 2012 at 2:18 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Gerd Hoffmann <kraxel@redhat.com> writes:
>
>> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>> ---
>>  hw/msix.c |    5 ++---
>>  1 files changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/msix.c b/hw/msix.c
>> index 800fc32..04345f2 100644
>> --- a/hw/msix.c
>> +++ b/hw/msix.c
>> @@ -307,9 +307,8 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
>>          return -EINVAL;
>>      }
>>
>> -    if (asprintf(&name, "%s-msix", dev->name) == -1) {
>> -        return -ENOMEM;
>> -    }
>> +    name = g_malloc(sizeof(dev->name) + 5);
>> +    snprintf(name, sizeof(dev->name) + 5, "%s-msix", dev->name);
>>
>>      memory_region_init(&dev->msix_exclusive_bar, name, MSIX_EXCLUSIVE_BAR_SIZE);
>
> What about g_strdup_printf()?

+1

In either case, free() below needs to be changed to g_free().
Gerd Hoffmann Aug. 13, 2012, 5:46 a.m. UTC | #3
On 08/10/12 16:18, Markus Armbruster wrote:
>> -    if (asprintf(&name, "%s-msix", dev->name) == -1) {
> 
> What about g_strdup_printf()?

Ah, nice.  Didn't know glib has this.

cheers,
  Gerd
diff mbox

Patch

diff --git a/hw/msix.c b/hw/msix.c
index 800fc32..04345f2 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -307,9 +307,8 @@  int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
         return -EINVAL;
     }
 
-    if (asprintf(&name, "%s-msix", dev->name) == -1) {
-        return -ENOMEM;
-    }
+    name = g_malloc(sizeof(dev->name) + 5);
+    snprintf(name, sizeof(dev->name) + 5, "%s-msix", dev->name);
 
     memory_region_init(&dev->msix_exclusive_bar, name, MSIX_EXCLUSIVE_BAR_SIZE);