From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yuy5y-0006yG-1B for qemu-devel@nongnu.org; Wed, 20 May 2015 03:07:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yuy5u-0005eL-Iv for qemu-devel@nongnu.org; Wed, 20 May 2015 03:07:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yuy5u-0005ca-De for qemu-devel@nongnu.org; Wed, 20 May 2015 03:07:10 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 7E0648F30B for ; Wed, 20 May 2015 07:07:09 +0000 (UTC) Date: Wed, 20 May 2015 12:36:50 +0530 From: Amit Shah Message-ID: <20150520070650.GH15452@grmbl.mre> References: <1431703178-12112-1-git-send-email-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1431703178-12112-1-git-send-email-dgilbert@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/1] Add qemu_get_counted_string to read a string prefixed by a count byte List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" Cc: qemu-devel@nongnu.org, quintela@redhat.com On (Fri) 15 May 2015 [16:19:38], Dr. David Alan Gilbert (git) wrote: > From: "Dr. David Alan Gilbert" > > and use it in loadvm_state and ram_load. > > Where ever it's used, check the return and error if it failed. > > Minor: ram_load was using a 257 byte array for its string, the > maximum length is 255 bytes + 0 terminator, so fix to 256 > > Signed-off-by: Dr. David Alan Gilbert (snip) > +/* > + * Get a string whose length is determined by a single preceding byte > + * A preallocated 256 byte buffer must be passed in. > + * Returns: len on success and a 0 terminated string in the buffer > + * else 0 > + * (Note a 0 length string will return 0 either way) > + */ > +size_t qemu_get_counted_string(QEMUFile *f, char buf[256]) > +{ > + size_t len = qemu_get_byte(f); > + size_t res = qemu_get_buffer(f, (uint8_t *)buf, len); > + > + buf[len] = 0; For safety, let's use buf[res] = 0; here... Amit