Received: from eggs.gnu.org ([2001:4830:134:3::10]:42059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQox0-0001RE-2p for qemu-devel@nongnu.org; Tue, 02 Feb 2016 23:21:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQoww-00089S-Qk for qemu-devel@nongnu.org; Tue, 02 Feb 2016 23:21:54 -0500 Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: <56B1663C.5040600@redhat.com> Date: Tue, 2 Feb 2016 23:21:42 -0500 Content-Transfer-Encoding: 7bit Message-Id: References: <1CF37786-9AAA-4E5E-B571-DE20E7A463EB@gmail.com> <20160202171606.GM18461@redhat.com> <72A30A67-5846-4835-B8D2-B7F545F76C0B@gmail.com> <20160202173111.GN18461@redhat.com> <70C3852E-1807-419B-9205-F24B5409EABF@gmail.com> <56B10282.1030609@redhat.com> <54A3ED84-6284-48A5-AF16-3B2BE27917C6@gmail.com> <56B12802.8010208@redhat.com> <56B1663C.5040600@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: Eric Blake Cc: Kevin Wolf , qemu-devel qemu-devel , Qemu-block On Feb 2, 2016, at 9:30 PM, Eric Blake wrote: > On 02/02/2016 06:15 PM, Programmingkid wrote: > >>> No, keep filename as a const char * pointer. It's easy to avoid use of >>> uninitialized memory. Try this: >>> >>> const char *filename; >>> char bsd_path[MAXPATHLEN] = ""; >>> ... >>> if (strncmp("/dev/cdrom"...) { >>> bsd_path = ... >>> } >>> ... >>> if (strncmp("/dev/"...) { >>> print_unmounting_directions(*bsd_path ? bsd_path : filename); >> >> At first I thought this code looked unusual, but it does work. Is this ok? >> >> #if defined(__APPLE__) && defined(__MACH__) >> /* if a physical device experienced an error while being opened */ >> if (strncmp((*bsd_path ? bsd_path : filename), "/dev/", 5) == 0) { >> print_unmounting_directions(*bsd_path ? bsd_path : filename); >> return -1; >> } > > A bit repetitive. You don't use filename after the fact, so shorter > would be: > > #if defined(__APPLE__)... > if (*bsd_path) { > filename = filename; > if (strncmp(filename, "/dev/"...) { > print...(filename); > Is this what you mean: #if defined(__APPLE__) && defined(__MACH__) /* if a physical device experienced an error while being opened */ filename = (*bsd_path ? bsd_path : filename); if (strncmp(filename, "/dev/", 5) == 0) { print_unmounting_directions(filename); return -1; } #endif /* defined(__APPLE__) && defined(__MACH__) */