From: Panu Matilainen Date: Thu, 12 Jun 2008 11:16:28 +0000 (+0300) Subject: Use HEADERGET_ALLOC instead of manual copy in longfilesizesTag() X-Git-Tag: tznext/4.11.0.1.tizen20130304~3904 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f361fe6a184b4d3772e234043a4f7dd647e41c9;p=tools%2Flibrpm-tizen.git Use HEADERGET_ALLOC instead of manual copy in longfilesizesTag() --- diff --git a/lib/tagexts.c b/lib/tagexts.c index cd400ae..966beeb 100644 --- a/lib/tagexts.c +++ b/lib/tagexts.c @@ -573,35 +573,30 @@ static int groupTag(Header h, rpmtd td) static int longfilesizesTag(Header h, rpmtd td) { int rc; - struct rpmtd_s filesizes; - rpm_loff_t *longsize; - - if (headerIsEntry(h, RPMTAG_LONGFILESIZES)) { - rc = headerGet(h, RPMTAG_LONGFILESIZES, &filesizes, HEADERGET_DEFAULT); - } else { - rc = headerGet(h, RPMTAG_FILESIZES, &filesizes, HEADERGET_MINMEM); - } /* - * Convert old 32bit file sizes to 64bit. Make a new copy of the - * data even for 64bit tags to have consistent behavior for rpmfi needs. + * If header has LONGFILESIZES then we've nothing special to do, + * otherwise convert 32bit FILESIZES to 64bit values. + * For consistency, always return malloced data. */ - td->type = RPM_INT64_TYPE; - td->count = filesizes.count; - td->flags = RPMTD_ALLOCED; - td->data = xmalloc(sizeof(*longsize) * rpmtdCount(&filesizes)); - - if (rpmtdType(&filesizes) == RPM_INT32_TYPE) { + if (headerIsEntry(h, RPMTAG_LONGFILESIZES)) { + rc = headerGet(h, RPMTAG_LONGFILESIZES, td, HEADERGET_ALLOC); + } else { + struct rpmtd_s filesizes; rpm_off_t *oldsize; + rpm_loff_t *longsize; + + rc = headerGet(h, RPMTAG_FILESIZES, &filesizes, HEADERGET_MINMEM); + td->type = RPM_INT64_TYPE; + td->count = filesizes.count; + td->flags = RPMTD_ALLOCED; + td->data = xmalloc(sizeof(*longsize) * rpmtdCount(&filesizes)); longsize = td->data; while ((oldsize = rpmtdNextUint32(&filesizes))) { *longsize++ = *oldsize; } - } else { - assert(rpmtdType(&filesizes) == RPM_INT64_TYPE); - memcpy(td->data, filesizes.data, sizeof(*longsize) * td->count); + rpmtdFreeData(&filesizes); } - rpmtdFreeData(&filesizes); return rc; }