Received: from eggs.gnu.org ([2001:4830:134:3::10]:51122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQgLG-0005sH-1t for qemu-devel@nongnu.org; Tue, 02 Feb 2016 14:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQgLE-0005dD-NQ for qemu-devel@nongnu.org; Tue, 02 Feb 2016 14:10:21 -0500 Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: <20160202173111.GN18461@redhat.com> Date: Tue, 2 Feb 2016 14:10:12 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <70C3852E-1807-419B-9205-F24B5409EABF@gmail.com> References: <1CF37786-9AAA-4E5E-B571-DE20E7A463EB@gmail.com> <20160202171606.GM18461@redhat.com> <72A30A67-5846-4835-B8D2-B7F545F76C0B@gmail.com> <20160202173111.GN18461@redhat.com> Subject: Re: [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: Kevin Wolf , qemu-devel qemu-devel , Qemu-block On Feb 2, 2016, at 12:31 PM, Daniel P. Berrange wrote: > On Tue, Feb 02, 2016 at 12:28:24PM -0500, Programmingkid wrote: >>=20 >> On Feb 2, 2016, at 12:16 PM, Daniel P. Berrange wrote: >>=20 >>> On Tue, Feb 02, 2016 at 12:08:31PM -0500, Programmingkid wrote: >>>> https://patchwork.ozlabs.org/patch/570128/ >>>>=20 >>>> Mac OS X can be picky when it comes to allowing the user >>>> to use physical devices in QEMU. Most mounted volumes >>>> appear to be off limits to QEMU. If an issue is detected, >>>> a message is displayed showing the user how to unmount a >>>> volume. Now QEMU uses both CD and DVD media. >>>>=20 >>>> Signed-off-by: John Arbuckle >>>>=20 >>>> --- >>>> Changed filename variable to a character array. >>>> Changed how filename was set to bsd_path's value by using = snprintf(). >>>=20 >>> Whats the rationale here ? Using pre-allocated fixed >>> length arrays is pretty bad practice in general, but >>> especially so for filenames >>=20 >> With an automatic variable there is no worry about when to release = it.=20 >>=20 >>>=20 >>>=20 >>>> @@ -2119,34 +2173,59 @@ static int hdev_open(BlockDriverState *bs, = QDict *options, int flags, >>>> int ret; >>>>=20 >>>> #if defined(__APPLE__) && defined(__MACH__) >>>> - const char *filename =3D qdict_get_str(options, "filename"); >>>=20 >>> [snip] >>>=20 >>>> + char filename[MAXPATHLEN]; >>>> + bool error_occurred =3D false; >>>> + snprintf(filename, MAXPATHLEN, "%s", qdict_get_str(options, = "filename")); >>>=20 >>> This is a step backwards compared to the original code >>> IMHO. There's no good reason to use a stack allocated >>> fixed array here - the code that follows would be >>> quite happy with the original 'const char *'. >>=20 >> Having to decide when and where to free memory is eliminated with >> automatic variables. The code looks cleaner without all the = g_free()'s. >> It also might eliminate possible memory leaks. >=20 > There was/is no leak because it qdict_get_str() returns 'const char *' = and > so nothing needs freeing. So your change is still a backwards steps = IMHO. char filename[MAXPATHLEN]; snprintf(filename, MAXPATHLEN, "%s", qdict_get_str(options, = "filename")); So you want the above to be changed so that it goes back to this: const char *filename =3D qdict_get_str(options, "filename"); then this code would have to be changed: snprintf(filename, MAXPATHLEN, "%s", bsd_path); qdict_put(options, "filename", qstring_from_str(filename)); I could change it to this: qdict_put(options, "filename", qstring_from_str(bsd_path)); If I did that, then this part would not be accurate anymore: if (strncmp(filename, "/dev/", 5) =3D=3D 0) { print_unmounting_directions(filename); return -1; } filename would be just "/dev/cdrom" for when the user uses the optical = drive. This would print incorrect unmounting directions.=20 I could add another variable that keeps track of the real device name, = but that would consume more memory. It is so much easier and simpler to = just use the fixed array.=