Received: from eggs.gnu.org ([2001:4830:134:3::10]:52781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUFHw-0005RA-9u for qemu-devel@nongnu.org; Tue, 25 Aug 2015 10:33:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUFHt-0001b5-13 for qemu-devel@nongnu.org; Tue, 25 Aug 2015 10:33:24 -0400 Received: from mail-qk0-x22c.google.com ([2607:f8b0:400d:c09::22c]:33862) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUFHs-0001au-LP for qemu-devel@nongnu.org; Tue, 25 Aug 2015 10:33:20 -0400 Received: by qkfh127 with SMTP id h127so101440782qkf.1 for ; Tue, 25 Aug 2015 07:33:20 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: <55DB98E1.600@redhat.com> Date: Tue, 25 Aug 2015 10:33:17 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <21D71986-15C6-4944-A758-1BFA1FFB4314@gmail.com> References: <29C62C49-06A5-4F99-8062-7269A28C29A3@gmail.com> <55DB98E1.600@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qdev-monitor.c: Add device id generation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel qemu-devel , Markus Armbruster On Aug 24, 2015, at 6:21 PM, Eric Blake wrote: > On 08/24/2015 12:53 PM, Programmingkid wrote: >> Add device ID generation to each device if an ID isn't given. >>=20 >> Signed-off-by: John Arbuckle >>=20 >> --- >=20 >> dev->id =3D id; >> + } else { /* create an id for a device if none is provided */ >> + static int device_id_count; >> + >> + /* Add one for '\0' character */ >> + char *device_id =3D (char *) malloc(sizeof(char) * >> + = MAX_NUM_DIGITS_FOR_USB_ID + 1); >> + sprintf(device_id, "%d", device_id_count++); >=20 > g_strdup_printf() is a lot nicer about avoiding the risk of arbitrary > overflow... I prefer to use well known functions that work well, but I guess it = shouldn't be too painful to use the g_strdup_printf() function. Do you really think there = is a possible overflow condition here? >=20 >> + dev->id =3D (const char *) device_id; >> + >> + /* if device_id_count >=3D 10^MAX_NUM_DIGITS_FOR_USB_ID */ >> + if (device_id_count >=3D pow(10, MAX_NUM_DIGITS_FOR_USB_ID)) = { >> + printf("Warning: Maximum number of device ID's = generated!\n\a"); >> + printf("Time for you to make your own device ID's.\n"); >=20 > besides, printf() is probably the wrong way to do error reporting, and Why do you believe this?=20 > we don't use \a BEL sequences anywhere else in qemu code. Innovation has to start somewhere :) >=20 >> + } >> } >>=20 >> if (dev->id) { >=20 > This if would now be a dead check if your patch is applied. I think you are right. It will be removed. >=20 >> object_property_add_child(qdev_get_peripheral(), dev->id, >> OBJECT(dev), NULL); >> - } else { >> - static int anon_count; >> - gchar *name =3D g_strdup_printf("device[%d]", anon_count++); >> - object_property_add_child(qdev_get_peripheral_anon(), name, >> - OBJECT(dev), NULL); >> - g_free(name); >> } >=20 > It looks like your goal was to move this code earlier, but you changed > enough aspects of it that I'm not sure what the right fix should be. I didn't want to move the code. It just was in a condition that would = never be true, so I thought why keep it. > --=20 > Eric Blake eblake redhat com +1-919-301-3266 Thank you very much for reviewing my patch.=20 > Libvirt virtualization library http://libvirt.org You work with this project? Any chance libvirt could support Mac OS X?