summaryrefslogtreecommitdiff
path: root/lib/headerfmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/headerfmt.c')
-rw-r--r--lib/headerfmt.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/headerfmt.c b/lib/headerfmt.c
index 2bb597fcc..51e27868d 100644
--- a/lib/headerfmt.c
+++ b/lib/headerfmt.c
@@ -415,7 +415,8 @@ static int parseFormat(headerSprintfArgs hsa, char * str,
}
/* Set justOne = 1 for non ARRAY tags */
- if (!(rpmTagGetReturnType(token->u.tag.tag) &
+ if (token->type == PTOK_TAG &&
+ !(rpmTagGetReturnType(token->u.tag.tag) &
RPM_ARRAY_RETURN_TYPE)) {
token->u.tag.justOne = 1;
}
@@ -688,8 +689,8 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token,
int element)
{
char * t, * te;
- int i, j, found;
- rpm_count_t count, numElements;
+ int i, j, found, singleItem;
+ int count, numElements;
sprintfToken spft;
int condNumFormats;
size_t need;
@@ -738,23 +739,32 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token,
break;
case PTOK_ARRAY:
- numElements = 0;
+ numElements = -1;
+ singleItem = 0;
found = 0;
spft = token->u.array.format;
+ /* get number of array items */
for (i = 0; i < token->u.array.numTokens; i++, spft++)
{
rpmtd td = NULL;
- if (spft->type != PTOK_TAG ||
- spft->u.tag.justOne) continue;
+ if (spft->type != PTOK_TAG) continue;
if (!(td = getData(hsa, spft->u.tag.tag))) {
continue;
}
- found = 1;
count = rpmtdCount(td);
+ found = 1;
- if (numElements > 1 && count != numElements)
+ if (spft->u.tag.justOne) {
+ if (count) {
+ singleItem = 1;
+ }
+ continue;
+ }
+
+
+ if (numElements > 0 && count != numElements)
switch (td->type) {
default:
hsaError(hsa,
@@ -769,6 +779,14 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token,
numElements = count;
}
+ if (numElements == -1 && singleItem) {
+ /* only justOne elements */
+ numElements = 1;
+ } else if (numElements == -1) {
+ /* nothing at all */
+ numElements = 0;
+ }
+
if (found) {
int isxml;