summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Festi <ffesti@redhat.com>2016-11-25 10:15:13 +0100
committerFlorian Festi <ffesti@redhat.com>2016-12-01 15:52:47 +0100
commitead9cdd587bbf052722f0f8598e0983e565e3415 (patch)
treef6790bbc14e4d3d7f36ee3a886b7b70dccd56be7
parent16c1f1fb89fe7e0f000a85d99fc298c0e45f91a8 (diff)
downloadrpm-ead9cdd587bbf052722f0f8598e0983e565e3415.tar.gz
Fix calculation of array size when formating query results.
In array output (square brackets in query format) all tags data sets need to have the same length. Single value tags may still be used. This patch fixes corner case where they are only single value items and ones where arrays with only one entries where treated as OK although they are not.
-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;