summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorNagy Gabor <ngaba@petra.hos.u-szeged.hu>2007-06-18 10:32:38 -0400
committerDan McGee <dan@archlinux.org>2007-06-26 11:49:00 -0400
commit7653bb93997f52848b54ab80868cd6da52808a75 (patch)
treee20036a929c3d87941b34d7bf25cd1838fd675be /lib/libalpm
parentda66bedf4f98897dfc350195314089028050fa7d (diff)
downloadpacman-7653bb93997f52848b54ab80868cd6da52808a75.tar.xz
Make alpm_splitdep immutable
The alpm_splitdep function formerly overwrote the input string, causing a few issues. Fix this. Signed-off-by: Nagy Gabor <ngaba@petra.hos.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/deps.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index ddb2c336..524136bd 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -437,10 +437,12 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
{
pmdepend_t *depend;
char *ptr = NULL;
+ char *newstr = NULL;
if(depstring == NULL) {
return(NULL);
}
+ newstr = strdup(depstring);
depend = malloc(sizeof(pmdepend_t));
if(depend == NULL) {
@@ -450,30 +452,32 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
/* Find a version comparator if one exists. If it does, set the type and
* increment the ptr accordingly so we can copy the right strings. */
- if((ptr = strstr(depstring, ">="))) {
+ if((ptr = strstr(newstr, ">="))) {
depend->mod = PM_DEP_MOD_GE;
*ptr = '\0';
ptr += 2;
- } else if((ptr = strstr(depstring, "<="))) {
+ } else if((ptr = strstr(newstr, "<="))) {
depend->mod = PM_DEP_MOD_LE;
*ptr = '\0';
ptr += 2;
- } else if((ptr = strstr(depstring, "="))) {
+ } else if((ptr = strstr(newstr, "="))) {
depend->mod = PM_DEP_MOD_EQ;
*ptr = '\0';
ptr += 1;
} else {
/* no version specified - copy in the name and return it */
depend->mod = PM_DEP_MOD_ANY;
- strncpy(depend->name, depstring, PKG_NAME_LEN);
+ strncpy(depend->name, newstr, PKG_NAME_LEN);
depend->version[0] = '\0';
+ free(newstr);
return(depend);
}
/* if we get here, we have a version comparator, copy the right parts
* to the right places */
- strncpy(depend->name, depstring, PKG_NAME_LEN);
+ strncpy(depend->name, newstr, PKG_NAME_LEN);
strncpy(depend->version, ptr, PKG_VERSION_LEN);
+ free(newstr);
return(depend);
}