FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 12-23-2011, 11:18 PM
Allan McRae
 
Default be_package: be more explicit parsing key/value pairs

On 24/12/11 06:40, Dan McGee wrote:
> This eliminates the need for strtrim() usage completely, instead relying
> on the fact that the only allowed delimiter between key and value is the
> " = " string.
>
> Signed-off-by: Dan McGee <dan@archlinux.org>
> ---
> lib/libalpm/be_package.c | 21 ++++++++++++---------
> 1 files changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
> index 41ecc75..c602996 100644
> --- a/lib/libalpm/be_package.c
> +++ b/lib/libalpm/be_package.c
> @@ -171,18 +171,21 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
> size_t len = _alpm_strip_newline(buf.line);
>
> linenum++;
> - if(len == 0 || buf.line[0] == '#') {
> + key = buf.line;
> + if(len == 0 || key[0] == '#') {
> continue;
> }
> - ptr = buf.line;
> - key = strsep(&ptr, "=");
> - if(key == NULL || ptr == NULL) {
> - _alpm_log(handle, ALPM_LOG_DEBUG, "%s: syntax error in description file line %d
",
> - newpkg->name ? newpkg->name : "error", linenum);
> + /* line is always in this format: "key = value"
> + * we can be sure the " = " exists, so look for that */
> + ptr = memchr(key, ' ', len);
> + if(!ptr || ptr - key + 2 > len || memcmp(ptr, " = ", 3) != 0) {


be_package.c: In function 'parse_descfile':
be_package.c:181:28: error: comparison between signed and unsigned
integer expressions [-Werror=sign-compare]

ptr - key + 2 is guaranteed to be > 0 so we can cast:

if(!ptr || (size_t)(ptr - key + 2) > len || memcmp(ptr, " = ", 3) != 0) {
 

Thread Tools




All times are GMT. The time now is 10:42 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org