summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-12-23 14:32:01 -0600
committerDan McGee <dan@archlinux.org>2011-12-23 14:37:03 -0600
commita7cb1509317e929043df973a9814145fecc99513 (patch)
tree88960ae35ebd719cde3f8cee3993a3692b55bbe2 /lib
parente28f321a486a310aeb3358ceff032793a88e5eb4 (diff)
be_package: be more explicit parsing key/value pairs
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/be_package.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 41ecc75a..c602996d 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\n",
- 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) {
+ _alpm_log(handle, ALPM_LOG_DEBUG,
+ "%s: syntax error in description file line %d\n",
+ newpkg->name ? newpkg->name : "error", linenum);
} else {
- key = _alpm_strtrim(key);
- while(*ptr == ' ') ptr++;
- ptr = _alpm_strtrim(ptr);
+ /* NULL the end of the key portion, move ptr to start of value */
+ *ptr = '\0';
+ ptr += 3;
if(strcmp(key, "pkgname") == 0) {
STRDUP(newpkg->name, ptr, return -1);
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);