summaryrefslogtreecommitdiff
path: root/lib/rpmds.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-09-11 06:34:36 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-09-11 08:08:34 +0300
commit25bef90870b883b66e8d914072b77585fab3b8a1 (patch)
treed8a75afd8c52de6935db9cfcc0ce6698db4f9736 /lib/rpmds.c
parent09373ec03a3537006c4252ff732273d4506e44d5 (diff)
downloadrpm-25bef90870b883b66e8d914072b77585fab3b8a1.tar.gz
rpm-25bef90870b883b66e8d914072b77585fab3b8a1.tar.bz2
rpm-25bef90870b883b66e8d914072b77585fab3b8a1.zip
Clean up rpmdsNewDNEVR() a bit
- Eliminate numerous repeated direct accesses to ds N, EVR and Flags, instead grab them into local variables at entry. This also makes the function safe illegal iterator values (ie calling when iteration not started), previously the bounds were not checked.
Diffstat (limited to 'lib/rpmds.c')
-rw-r--r--lib/rpmds.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/rpmds.c b/lib/rpmds.c
index 82aec528b..fdc0ae0ca 100644
--- a/lib/rpmds.c
+++ b/lib/rpmds.c
@@ -166,23 +166,26 @@ exit:
char * rpmdsNewDNEVR(const char * dspfx, const rpmds ds)
{
+ const char * N = rpmdsN(ds);
+ const char * EVR = rpmdsEVR(ds);
+ rpmsenseFlags Flags = rpmdsFlags(ds);
char * tbuf, * t;
size_t nb;
nb = 0;
if (dspfx) nb += strlen(dspfx) + 1;
- if (ds->N[ds->i]) nb += strlen(ds->N[ds->i]);
+ if (N) nb += strlen(N);
/* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
- if (ds->Flags != NULL && (ds->Flags[ds->i] & RPMSENSE_SENSEMASK)) {
+ if (Flags & RPMSENSE_SENSEMASK) {
if (nb) nb++;
- if (ds->Flags[ds->i] & RPMSENSE_LESS) nb++;
- if (ds->Flags[ds->i] & RPMSENSE_GREATER) nb++;
- if (ds->Flags[ds->i] & RPMSENSE_EQUAL) nb++;
+ if (Flags & RPMSENSE_LESS) nb++;
+ if (Flags & RPMSENSE_GREATER) nb++;
+ if (Flags & RPMSENSE_EQUAL) nb++;
}
/* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
- if (ds->EVR != NULL && ds->EVR[ds->i] && *ds->EVR[ds->i]) {
+ if (EVR && *EVR) {
if (nb) nb++;
- nb += strlen(ds->EVR[ds->i]);
+ nb += strlen(EVR);
}
t = tbuf = xmalloc(nb + 1);
@@ -190,19 +193,19 @@ char * rpmdsNewDNEVR(const char * dspfx, const rpmds ds)
t = stpcpy(t, dspfx);
*t++ = ' ';
}
- if (ds->N[ds->i])
- t = stpcpy(t, ds->N[ds->i]);
+ if (N)
+ t = stpcpy(t, N);
/* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
- if (ds->Flags != NULL && (ds->Flags[ds->i] & RPMSENSE_SENSEMASK)) {
+ if (Flags & RPMSENSE_SENSEMASK) {
if (t != tbuf) *t++ = ' ';
- if (ds->Flags[ds->i] & RPMSENSE_LESS) *t++ = '<';
- if (ds->Flags[ds->i] & RPMSENSE_GREATER) *t++ = '>';
- if (ds->Flags[ds->i] & RPMSENSE_EQUAL) *t++ = '=';
+ if (Flags & RPMSENSE_LESS) *t++ = '<';
+ if (Flags & RPMSENSE_GREATER) *t++ = '>';
+ if (Flags & RPMSENSE_EQUAL) *t++ = '=';
}
/* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
- if (ds->EVR != NULL && ds->EVR[ds->i] && *ds->EVR[ds->i]) {
+ if (EVR && *EVR) {
if (t != tbuf) *t++ = ' ';
- t = stpcpy(t, ds->EVR[ds->i]);
+ t = stpcpy(t, EVR);
}
*t = '\0';
return tbuf;