From 06ceac214a9ad3821042c35c392ce95ffd0e22a3 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 09:09:36 +0300 Subject: [PATCH 01/17] Eliminate anonymous embedded struct use in filelist C++ doesn't like this... --- build/files.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build/files.c b/build/files.c index ed6a9b56b4..32e9be9d0c 100644 --- a/build/files.c +++ b/build/files.c @@ -140,6 +140,11 @@ typedef struct FileEntry_s { int isDir; } * FileEntry; +struct FileEntries_s { + struct FileEntry_s defEntry; + struct FileEntry_s curEntry; +}; + typedef struct specialDir_s { char * dirname; ARGV_t files; @@ -150,11 +155,7 @@ typedef struct specialDir_s { int entriesCount; int entriesAlloced; - struct { - struct FileEntry_s defEntry; - struct FileEntry_s curEntry; - } *entries; - + struct FileEntries_s *entries; } * specialDir; typedef struct FileRecords_s { From 8793b1f508cd761373566a003879e1673d22c67d Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 09:20:55 +0300 Subject: [PATCH 02/17] Drop a redundant helper variable --- build/parsePrep.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build/parsePrep.c b/build/parsePrep.c index 60d478f9dd..3910949eea 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -72,7 +72,6 @@ static char *doPatch(rpmSpec spec, uint32_t c, int strip, const char *db, rpmlog(RPMLOG_ERR, _("No patch number %u\n"), c); goto exit; } - const char *fn = sp->path; if (db) { rasprintf(&arg_backup, "-b --suffix %s", db); @@ -96,10 +95,10 @@ static char *doPatch(rpmSpec spec, uint32_t c, int strip, const char *db, setUtc ? " -Z" : ""); /* Avoid the extra cost of fork and pipe for uncompressed patches */ - if (notCompressed(fn)) { - patchcmd = rpmExpand("%{__patch} ", args, " < ", fn, NULL); + if (notCompressed(sp->path)) { + patchcmd = rpmExpand("%{__patch} ", args, " < ", sp->path, NULL); } else { - patchcmd = rpmExpand("{ %{__rpmuncompress} ", fn, " || echo patch_fail ; } | " + patchcmd = rpmExpand("{ %{__rpmuncompress} ", sp->path, " || echo patch_fail ; } | " "%{__patch} ", args, NULL); } From 100ad29c2b844e835e9e684cbf036c1787a8c644 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 09:19:53 +0300 Subject: [PATCH 03/17] String literals should be const char * In particular, spec->nextline is written to, so pointing it to a string literal is undefined behavior. NULL seems to achieve the same. --- build/files.c | 2 +- build/parseSpec.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/files.c b/build/files.c index 32e9be9d0c..e8f4568065 100644 --- a/build/files.c +++ b/build/files.c @@ -883,7 +883,7 @@ static VFA_t const virtualAttrs[] = { static rpmRC parseForSimple(char * buf, FileEntry cur, ARGV_t * fileNames) { char *s, *t, *end; - char *delim = " \t\n"; + const char *delim = " \t\n"; int quotes = 0; rpmRC res = RPMRC_OK; int allow_relative = (RPMFILE_PUBKEY|RPMFILE_DOC|RPMFILE_LICENSE); diff --git a/build/parseSpec.c b/build/parseSpec.c index b000523baf..0e0764576f 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -345,7 +345,7 @@ static int copyNextLineFromOFI(rpmSpec spec, OFI_t *ofi, int strip) /* If it doesn't, ask for one more line. */ if (pc || bc || xc || nc ) { - spec->nextline = ""; + spec->nextline = NULL; return 1; } spec->lbufOff = 0; From ff2d9a219469bfad95909a7d32729be860feda47 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 09:31:50 +0300 Subject: [PATCH 04/17] rpmTag/rpmTagVal type pedantry rpmTag doesn't include anything suitable for a sentinel value, so don't use it in array initializers. rpmTagVal works for that, but it's an unsigned type so use 0 instead of -1. --- build/parsePreamble.c | 2 +- lib/relocation.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/parsePreamble.c b/build/parsePreamble.c index 3bb4fc2b05..72567cee63 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -574,7 +574,7 @@ static struct optionalTag { { RPMTAG_TRANSLATIONURL, "%{translationurl}" }, { RPMTAG_UPSTREAMRELEASES, "%{upstreamreleases}" }, { RPMTAG_MODULARITYLABEL, "%{modularitylabel}"}, - { -1, NULL } + { 0, NULL } }; /** diff --git a/lib/relocation.c b/lib/relocation.c index 2919b4873b..9f36d372ff 100644 --- a/lib/relocation.c +++ b/lib/relocation.c @@ -351,7 +351,7 @@ assert(fn != NULL); /* XXX can't happen */ */ static struct tagMacro { const char *macroname; /*!< Macro name to define. */ - rpmTag tag; /*!< Header tag to use for value. */ + rpmTagVal tag; /*!< Header tag to use for value. */ } const tagMacros[] = { { "name", RPMTAG_NAME }, { "version", RPMTAG_VERSION }, From 682b3680a4a664f54c17652095f8fa7920451716 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 09:34:26 +0300 Subject: [PATCH 05/17] signal() returns sighandler_t, not void * --- build/rpmfc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/rpmfc.c b/build/rpmfc.c index 15ec1ea68a..38bffcd301 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -295,7 +295,7 @@ static int getOutputFrom(ARGV_t argv, return -1; } - void *oldhandler = signal(SIGPIPE, SIG_IGN); + sighandler_t oldhandler = signal(SIGPIPE, SIG_IGN); child = fork(); if (child < 0) { From 5ca3c211dde6e57d43ccce0110b491f8013fedbd Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 22 Mar 2024 12:05:55 +0200 Subject: [PATCH 06/17] Avoid rpm tag signedness issues in build tables + related code rpmTagVal is unsigned so we can't really have these -1's in there. Tag works for this purpose just as well - assuming I spotted all the explicit comparisons to -1 in the depMsgs code. --- build/rpmfc.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/build/rpmfc.c b/build/rpmfc.c index 38bffcd301..3b0400fef3 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -1479,37 +1479,37 @@ static struct DepMsg_s depMsgs[] = { RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION, RPMTAG_REQUIREFLAGS, RPMSENSE_INTERP, 0 }, { "Requires(rpmlib)", { NULL, "rpmlib", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_RPMLIB, 0 }, { "Requires(verify)", { NULL, "verify", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_SCRIPT_VERIFY, 0 }, { "Requires(pre)", { NULL, "pre", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_SCRIPT_PRE, 0 }, { "Requires(post)", { NULL, "post", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_SCRIPT_POST, 0 }, { "Requires(preun)", { NULL, "preun", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_SCRIPT_PREUN, 0 }, { "Requires(postun)", { NULL, "postun", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_SCRIPT_POSTUN, 0 }, { "Requires(pretrans)", { NULL, "pretrans", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_PRETRANS, 0 }, { "Requires(posttrans)", { NULL, "posttrans", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_POSTTRANS, 0 }, { "Requires(preuntrans)", { NULL, "preuntrans", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_PREUNTRANS, 0 }, { "Requires(postuntrans)", { NULL, "postuntrans", NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, + 0, 0, RPMTAG_REQUIREFLAGS, RPMSENSE_POSTUNTRANS, 0 }, { "Requires", { "%{?__find_requires}", NULL, NULL, NULL }, - -1, -1, RPMTAG_REQUIREFLAGS, /* XXX inherit name/version arrays */ + 0, 0, RPMTAG_REQUIREFLAGS, /* XXX inherit name/version arrays */ RPMSENSE_FIND_REQUIRES|RPMSENSE_TRIGGERIN|RPMSENSE_TRIGGERUN|RPMSENSE_TRIGGERPOSTUN|RPMSENSE_TRIGGERPREIN, 0 }, { "Conflicts", { "%{?__find_conflicts}", NULL, NULL, NULL }, RPMTAG_CONFLICTNAME, RPMTAG_CONFLICTVERSION, RPMTAG_CONFLICTFLAGS, @@ -1546,7 +1546,7 @@ static void printDeps(rpmfc fc) int bingo = 0; for (dm = DepMsgs; dm->msg != NULL; dm++) { - if (dm->ntag != -1) { + if (dm->ntag) { ds = rpmfcDependencies(fc, dm->ntag); } if (dm->ftag == 0) @@ -1630,7 +1630,7 @@ static rpmRC rpmfcApplyExternal(rpmfc fc) } /* Parse dependencies into header */ - rc = parseRCPOT(NULL, fc->pkg, getStringBuf(sb_stdout), dm->ntag != -1 ? dm->ntag : RPMTAG_REQUIRENAME, 0, tagflags, addReqProvPkg, NULL); + rc = parseRCPOT(NULL, fc->pkg, getStringBuf(sb_stdout), dm->ntag ? dm->ntag : RPMTAG_REQUIRENAME, 0, tagflags, addReqProvPkg, NULL); freeStringBuf(sb_stdout); if (rc) { From f727e66e714e0e0bd48ef8f8ee5c5bc93ce11e21 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 09:41:04 +0300 Subject: [PATCH 07/17] Fix couple of RPMTAG/RPMDBI type mismatches --- lib/depends.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/depends.c b/lib/depends.c index d336e14d7c..3cb0a90bd9 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -1028,7 +1028,7 @@ int rpmtsCheck(rpmts ts) confilehash = filedepHashCreate(257, sidHash, sidCmp, NULL, NULL); connothash = depexistsHashCreate(257, sidHash, sidCmp, NULL); connotfilehash = filedepHashCreate(257, sidHash, sidCmp, NULL, NULL); - addIndexToDepHashes(ts, RPMTAG_CONFLICTNAME, NULL, confilehash, connothash, connotfilehash); + addIndexToDepHashes(ts, RPMDBI_CONFLICTNAME, NULL, confilehash, connothash, connotfilehash); if (!filedepHashNumKeys(confilehash)) confilehash = filedepHashFree(confilehash); if (!depexistsHashNumKeys(connothash)) @@ -1040,7 +1040,7 @@ int rpmtsCheck(rpmts ts) reqfilehash = filedepHashCreate(8191, sidHash, sidCmp, NULL, NULL); reqnothash = depexistsHashCreate(257, sidHash, sidCmp, NULL); reqnotfilehash = filedepHashCreate(257, sidHash, sidCmp, NULL, NULL); - addIndexToDepHashes(ts, RPMTAG_REQUIRENAME, NULL, reqfilehash, reqnothash, reqnotfilehash); + addIndexToDepHashes(ts, RPMDBI_REQUIRENAME, NULL, reqfilehash, reqnothash, reqnotfilehash); if (!filedepHashNumKeys(reqfilehash)) reqfilehash = filedepHashFree(reqfilehash); if (!depexistsHashNumKeys(reqnothash)) From 386167a6668ddf24eac860de17850fc8ea6961f5 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 10:07:51 +0300 Subject: [PATCH 08/17] Use proper callback types in psm notify wrapper --- lib/fsm.h | 3 ++- lib/psm.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fsm.h b/lib/fsm.h index 25b129de27..616e93aa20 100644 --- a/lib/fsm.h +++ b/lib/fsm.h @@ -7,6 +7,7 @@ */ #include +#include #ifdef __cplusplus extern "C" { @@ -34,7 +35,7 @@ RPM_GNUC_INTERNAL int rpmfiArchiveReadToFilePsm(rpmfi fi, FD_t fd, int nodigest, rpmpsm psm); RPM_GNUC_INTERNAL -void rpmpsmNotify(rpmpsm psm, int what, rpm_loff_t amount); +void rpmpsmNotify(rpmpsm psm, rpmCallbackType what, rpm_loff_t amount); #ifdef __cplusplus } #endif diff --git a/lib/psm.c b/lib/psm.c index cf2c145016..4d7d96aade 100644 --- a/lib/psm.c +++ b/lib/psm.c @@ -683,7 +683,7 @@ static rpmpsm rpmpsmNew(rpmts ts, rpmte te, pkgGoal goal) return psm; } -void rpmpsmNotify(rpmpsm psm, int what, rpm_loff_t amount) +void rpmpsmNotify(rpmpsm psm, rpmCallbackType what, rpm_loff_t amount) { if (psm) { int changed = 0; From e6f9853c2112c8e7258623ed901a3e6b0804e4ef Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 10:18:09 +0300 Subject: [PATCH 09/17] Introduce and use RPMRICHOP_NONE to fix int/enum mismatches --- include/rpm/rpmds.h | 1 + lib/rpmds.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/rpm/rpmds.h b/include/rpm/rpmds.h index e0779ab59f..6f6b6c678e 100644 --- a/include/rpm/rpmds.h +++ b/include/rpm/rpmds.h @@ -456,6 +456,7 @@ int rpmdsRpmlibPool(rpmstrPool pool, rpmds * dsp, const void * tblp); typedef enum rpmrichOp_e { + RPMRICHOP_NONE = 0, RPMRICHOP_SINGLE = 1, RPMRICHOP_AND = 2, RPMRICHOP_OR = 3, diff --git a/lib/rpmds.c b/lib/rpmds.c index fc00d9fb84..14727ed96a 100644 --- a/lib/rpmds.c +++ b/lib/rpmds.c @@ -1246,7 +1246,7 @@ static struct RichOpComp { { "else", RPMRICHOP_ELSE}, { "with", RPMRICHOP_WITH}, { "without", RPMRICHOP_WITHOUT}, - { NULL, 0 }, + { NULL, RPMRICHOP_NONE }, }; int rpmdsIsRich(rpmds dep) @@ -1368,7 +1368,7 @@ static rpmRC rpmrichParseCheck(rpmrichOp op, int check, char **emsg) static rpmRC rpmrichParseInternal(const char **dstrp, char **emsg, rpmrichParseFunction cb, void *cbdata, int *checkp) { const char *p = *dstrp, *pe; - rpmrichOp op = RPMRICHOP_SINGLE, firstop = RPMRICHOP_SINGLE, chainop = 0; + rpmrichOp op = RPMRICHOP_SINGLE, firstop = RPMRICHOP_SINGLE, chainop = RPMRICHOP_NONE; int check = checkp ? *checkp : 0; if (cb && cb(cbdata, RPMRICH_PARSE_ENTER, p, 0, 0, 0, 0, op, emsg) != RPMRC_OK) @@ -1415,7 +1415,7 @@ static rpmRC rpmrichParseInternal(const char **dstrp, char **emsg, rpmrichParseF firstop = op; if (op == RPMRICHOP_ELSE && (chainop == RPMRICHOP_IF || chainop == RPMRICHOP_UNLESS)) - chainop = 0; + chainop = RPMRICHOP_NONE; if (chainop && op != chainop) { if (emsg) rasprintf(emsg, _("Cannot chain different ops")); From 0a60357815b5bf0b49b245e4418a8e601804eacd Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 10:37:41 +0300 Subject: [PATCH 10/17] Add c++ guards to internal headers and sources as needed --- lib/rpmug.h | 9 +++++++++ rpmio/rpmpgp_sequoia.c | 9 +++++++++ sign/rpmsignfiles.c | 1 - sign/rpmsignfiles.h | 3 +++ tools/cliutils.h | 8 ++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/rpmug.h b/lib/rpmug.h index 9f7001a1f4..bca3ce3e89 100644 --- a/lib/rpmug.h +++ b/lib/rpmug.h @@ -4,6 +4,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + RPM_GNUC_INTERNAL int rpmugUid(const char * name, uid_t * uid); @@ -19,4 +23,9 @@ const char * rpmugGname(gid_t gid); RPM_GNUC_INTERNAL void rpmugFree(void); +#ifdef __cplusplus +} +#endif + + #endif /* _RPMUG_H */ diff --git a/rpmio/rpmpgp_sequoia.c b/rpmio/rpmpgp_sequoia.c index d0b673953b..95f7cc90f8 100644 --- a/rpmio/rpmpgp_sequoia.c +++ b/rpmio/rpmpgp_sequoia.c @@ -24,6 +24,10 @@ return _##f args; \ } +#ifdef __cplusplus +extern "C" { +#endif + W(int, pgpSignatureType, (pgpDigParams _digp), (_digp)) W(pgpDigParams, pgpDigParamsFree, (pgpDigParams digp), (digp)) W(int, pgpDigParamsCmp, (pgpDigParams p1, pgpDigParams p2), (p1, p2)) @@ -80,3 +84,8 @@ W(int, rpmDigestUpdate, (DIGEST_CTX ctx, const void * data, size_t len), W(int, rpmDigestFinal, (DIGEST_CTX ctx, void ** datap, size_t *lenp, int asAscii), (ctx, datap, lenp, asAscii)) + +#ifdef __cplusplus +} +#endif + diff --git a/sign/rpmsignfiles.c b/sign/rpmsignfiles.c index fd5c72931a..ecd49aac55 100644 --- a/sign/rpmsignfiles.c +++ b/sign/rpmsignfiles.c @@ -5,7 +5,6 @@ */ #include "system.h" -#include "imaevm.h" #include #include diff --git a/sign/rpmsignfiles.h b/sign/rpmsignfiles.h index a21a006125..48d07a0f3b 100644 --- a/sign/rpmsignfiles.h +++ b/sign/rpmsignfiles.h @@ -8,6 +8,9 @@ extern "C" { #endif +/* This doesn't have c++ guards on its own */ +#include + /** * Sign file digests in header into signature header * @param sigh package signature header diff --git a/tools/cliutils.h b/tools/cliutils.h index b5deee1bac..f0e16e2828 100644 --- a/tools/cliutils.h +++ b/tools/cliutils.h @@ -13,6 +13,10 @@ /* "normalized" exit: avoid overflowing and xargs special value 255 */ #define RETVAL(rc) (((rc) > 254) ? 254 : (rc)) +#ifdef __cplusplus +extern "C" { +#endif + RPM_GNUC_NORETURN void argerror(const char * desc); @@ -22,4 +26,8 @@ int initPipe(void); int finishPipe(void); +#ifdef __cplusplus +} +#endif + #endif /* _CLIUTIL_H */ From 290155872a509d017ae55f01255ecab36c78445b Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 1 Mar 2024 09:37:24 +0200 Subject: [PATCH 11/17] Avoid relying on writable string literals in macros This hack here is illegal in c++. Just strdup() the silly little string, it's not like this is a performance critical spot. --- rpmio/macro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index fd30373b1b..63190b87da 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1353,7 +1353,8 @@ static void doFoo(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed) } else if (rstreq("getconfdir", me->name)) { b = (char *)rpmConfigDir(); } else if (rstreq("exists", me->name)) { - b = (access(argv[1], F_OK) == 0) ? "1" : "0"; + buf = xstrdup((access(argv[1], F_OK) == 0) ? "1" : "0"); + b = buf; } if (b) { From fbe4ebb410c8dc907a340fa06366180453bb9d43 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 22 Mar 2024 10:39:26 +0200 Subject: [PATCH 12/17] Lift %shrink out of doFoo() This really belongs to a separate function in the first place, and doing so allows us to turn 'b' into a const char *, which in turn makes the assignment to string literal "" in the url2path case legitimate. Fun times and no functional changes. --- rpmio/macro.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 63190b87da..5769992d45 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1294,10 +1294,32 @@ static void doGetncpus(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *pa rpmMacroBufAppendStr(mb, buf); } +/* + * shrink body by removing all leading and trailing whitespaces and + * reducing intermediate whitespaces to a single space character. + */ +static char *doShrink(const char *arg) +{ + char *b, *p, c, last_c = ' '; + char *buf = b = p = xstrdup(arg); + while ((c = *p++) != 0) { + if (risspace(c)) { + if (last_c == ' ') + continue; + c = ' '; + } + *b++ = last_c = c; + } + if (b != buf && b[-1] == ' ') + b--; + *b = 0; + return buf; +} + static void doFoo(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed) { char *buf = NULL; - char *b = NULL; + const char *b = NULL; if (rstreq("basename", me->name)) { buf = xstrdup(argv[1]); @@ -1306,24 +1328,7 @@ static void doFoo(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed) buf = xstrdup(argv[1]); b = dirname(buf); } else if (rstreq("shrink", me->name)) { - /* - * shrink body by removing all leading and trailing whitespaces and - * reducing intermediate whitespaces to a single space character. - */ - char *p, c, last_c = ' '; - buf = b = p = xstrdup(argv[1]); - while ((c = *p++) != 0) { - if (risspace(c)) { - if (last_c == ' ') - continue; - c = ' '; - } - *b++ = last_c = c; - } - if (b != buf && b[-1] == ' ') - b--; - *b = 0; - b = buf; + b = buf = doShrink(argv[1]); } else if (rstreq("quote", me->name)) { if (mb->flags & RPMEXPAND_KEEP_QUOTED) { b = buf = unsplitQuoted(argv + 1, " "); From aa273541a0bdfe365619eba78a05abe61955369c Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 1 Mar 2024 09:56:11 +0200 Subject: [PATCH 13/17] Work around C++ restriction on forward declarations Forward declarations to structs like we have in rpmio isn't legitimate C++, as a minimal bandaid solution declare them as extern in the internal header, and limit visibility. --- rpmio/rpmio.c | 30 +++++++----------------------- rpmio/rpmio_internal.h | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 60fc3286d9..465fbc53ba 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -21,7 +21,6 @@ #include "debug.h" typedef struct FDSTACK_s * FDSTACK_t; -typedef const struct FDIO_s * FDIO_t; struct FDSTACK_s { FDIO_t io; @@ -144,21 +143,6 @@ struct FDIO_s { fdio_fstrerr_function_t _fstrerr; }; -/* forward refs */ -static const FDIO_t fdio; -static const FDIO_t ufdio; -static const FDIO_t gzdio; -#ifdef HAVE_BZLIB_H -static const FDIO_t bzdio; -#endif -#ifdef HAVE_LZMA_H -static const FDIO_t xzdio; -static const FDIO_t lzdio; -#endif -#ifdef HAVE_ZSTD -static const FDIO_t zstdio; -#endif - /** \ingroup rpmio * Update digest(s) attached to fd. */ @@ -420,7 +404,7 @@ static const struct FDIO_s fdio_s = { fdRead, fdWrite, fdSeek, fdClose, fdOpen, NULL, fdFlush, fdTell, fdError, fdStrerr, }; -static const FDIO_t fdio = &fdio_s ; +const FDIO_t fdio = &fdio_s ; off_t ufdCopy(FD_t sfd, FD_t tfd) { @@ -542,7 +526,7 @@ static const struct FDIO_s ufdio_s = { fdRead, fdWrite, fdSeek, fdClose, ufdOpen, NULL, fdFlush, fdTell, fdError, fdStrerr }; -static const FDIO_t ufdio = &ufdio_s ; +const FDIO_t ufdio = &ufdio_s ; /* =============================================================== */ /* Support for GZIP library. */ @@ -652,7 +636,7 @@ static const struct FDIO_s gzdio_s = { gzdRead, gzdWrite, gzdSeek, gzdClose, NULL, gzdFdopen, gzdFlush, gzdTell, zfdError, zfdStrerr }; -static const FDIO_t gzdio = &gzdio_s ; +const FDIO_t gzdio = &gzdio_s ; /* =============================================================== */ /* Support for BZIP2 library. */ @@ -723,7 +707,7 @@ static const struct FDIO_s bzdio_s = { bzdRead, bzdWrite, NULL, bzdClose, NULL, bzdFdopen, bzdFlush, NULL, zfdError, zfdStrerr }; -static const FDIO_t bzdio = &bzdio_s ; +const FDIO_t bzdio = &bzdio_s ; #endif /* HAVE_BZLIB_H */ @@ -983,14 +967,14 @@ static struct FDIO_s xzdio_s = { lzdRead, lzdWrite, NULL, lzdClose, NULL, xzdFdopen, lzdFlush, NULL, zfdError, zfdStrerr }; -static const FDIO_t xzdio = &xzdio_s; +const FDIO_t xzdio = &xzdio_s; static struct FDIO_s lzdio_s = { "lzdio", "lzma", lzdRead, lzdWrite, NULL, lzdClose, NULL, lzdFdopen, lzdFlush, NULL, zfdError, zfdStrerr }; -static const FDIO_t lzdio = &lzdio_s; +const FDIO_t lzdio = &lzdio_s; #endif /* HAVE_LZMA_H */ @@ -1292,7 +1276,7 @@ static const struct FDIO_s zstdio_s = { zstdRead, zstdWrite, NULL, zstdClose, NULL, zstdFdopen, zstdFlush, NULL, zfdError, zfdStrerr }; -static const FDIO_t zstdio = &zstdio_s ; +const FDIO_t zstdio = &zstdio_s ; #endif /* HAVE_ZSTD */ diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h index fb82b04bdc..2cc9dfeadf 100644 --- a/rpmio/rpmio_internal.h +++ b/rpmio/rpmio_internal.h @@ -47,6 +47,29 @@ int rpmioSlurp(const char * fn, */ void rpmSetCloseOnExec(void); +typedef const struct FDIO_s * FDIO_t; + +RPM_GNUC_INTERNAL +extern const FDIO_t fdio; +RPM_GNUC_INTERNAL +extern const FDIO_t ufdio; +RPM_GNUC_INTERNAL +extern const FDIO_t gzdio; +#ifdef HAVE_BZLIB_H +RPM_GNUC_INTERNAL +extern const FDIO_t bzdio; +#endif +#ifdef HAVE_LZMA_H +RPM_GNUC_INTERNAL +extern const FDIO_t xzdio; +RPM_GNUC_INTERNAL +extern const FDIO_t lzdio; +#endif +#ifdef HAVE_ZSTD +RPM_GNUC_INTERNAL +extern const FDIO_t zstdio; +#endif + #ifdef __cplusplus } #endif From 99d925cfa53608397be6d76d34a78111a873bdbe Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 1 Mar 2024 10:11:32 +0200 Subject: [PATCH 14/17] Wrap rpmio inner file pointer access behind typed helper function Otherwise we'd need casts for each of these accesses, having a function allows doing more if necessary. --- rpmio/rpmio.c | 57 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 465fbc53ba..f711e1272b 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -531,6 +531,10 @@ const FDIO_t ufdio = &ufdio_s ; /* =============================================================== */ /* Support for GZIP library. */ #include +static gzFile gzdFp(FDSTACK_t fps) +{ + return (gzFile)fps->fp; +} static FD_t gzdFdopen(FD_t fd, int fdno, const char *fmode) { @@ -546,14 +550,14 @@ static FD_t gzdFdopen(FD_t fd, int fdno, const char *fmode) static int gzdFlush(FDSTACK_t fps) { - gzFile gzfile = fps->fp; + gzFile gzfile = gzdFp(fps); if (gzfile == NULL) return -2; return gzflush(gzfile, Z_SYNC_FLUSH); /* XXX W2DO? */ } static void gzdSetError(FDSTACK_t fps) { - gzFile gzfile = fps->fp; + gzFile gzfile = gzdFp(fps); int zerror = 0; fps->errcookie = gzerror(gzfile, &zerror); if (zerror == Z_ERRNO) { @@ -564,7 +568,7 @@ static void gzdSetError(FDSTACK_t fps) static ssize_t gzdRead(FDSTACK_t fps, void * buf, size_t count) { - gzFile gzfile = fps->fp; + gzFile gzfile = gzdFp(fps); ssize_t rc; if (gzfile == NULL) return -2; /* XXX can't happen */ @@ -580,7 +584,7 @@ static ssize_t gzdWrite(FDSTACK_t fps, const void * buf, size_t count) gzFile gzfile; ssize_t rc; - gzfile = fps->fp; + gzfile = gzdFp(fps); if (gzfile == NULL) return -2; /* XXX can't happen */ rc = gzwrite(gzfile, (void *)buf, count); @@ -593,7 +597,7 @@ static int gzdSeek(FDSTACK_t fps, off_t pos, int whence) { off_t p = pos; int rc; - gzFile gzfile = fps->fp; + gzFile gzfile = gzdFp(fps); if (gzfile == NULL) return -2; /* XXX can't happen */ @@ -605,7 +609,7 @@ static int gzdSeek(FDSTACK_t fps, off_t pos, int whence) static int gzdClose(FDSTACK_t fps) { - gzFile gzfile = fps->fp; + gzFile gzfile = gzdFp(fps); int rc; if (gzfile == NULL) return -2; /* XXX can't happen */ @@ -618,7 +622,7 @@ static int gzdClose(FDSTACK_t fps) static off_t gzdTell(FDSTACK_t fps) { off_t pos = -1; - gzFile gzfile = fps->fp; + gzFile gzfile = gzdFp(fps); if (gzfile != NULL) { #ifdef HAVE_GZSEEK @@ -644,6 +648,11 @@ const FDIO_t gzdio = &gzdio_s ; #include +static BZFILE *bzdFp(FDSTACK_t fps) +{ + return (BZFILE *)fps->fp; +} + static FD_t bzdFdopen(FD_t fd, int fdno, const char * fmode) { BZFILE *bzfile = BZ2_bzdopen(fdno, fmode); @@ -658,12 +667,12 @@ static FD_t bzdFdopen(FD_t fd, int fdno, const char * fmode) static int bzdFlush(FDSTACK_t fps) { - return BZ2_bzflush(fps->fp); + return BZ2_bzflush(bzdFp(fps)); } static ssize_t bzdRead(FDSTACK_t fps, void * buf, size_t count) { - BZFILE *bzfile = fps->fp; + BZFILE *bzfile = bzdFp(fps); ssize_t rc = 0; if (bzfile) @@ -679,7 +688,7 @@ static ssize_t bzdRead(FDSTACK_t fps, void * buf, size_t count) static ssize_t bzdWrite(FDSTACK_t fps, const void * buf, size_t count) { - BZFILE *bzfile = fps->fp; + BZFILE *bzfile = bzdFp(fps); ssize_t rc; rc = BZ2_bzwrite(bzfile, (void *)buf, count); @@ -692,7 +701,7 @@ static ssize_t bzdWrite(FDSTACK_t fps, const void * buf, size_t count) static int bzdClose(FDSTACK_t fps) { - BZFILE *bzfile = fps->fp; + BZFILE *bzfile = bzdFp(fps); if (bzfile == NULL) return -2; @@ -908,6 +917,11 @@ static FD_t xzdFdopen(FD_t fd, int fdno, const char * fmode) return fd; } +static LZFILE *lzdFp(FDSTACK_t fps) +{ + return (LZFILE*)fps->fp; +} + static FD_t lzdFdopen(FD_t fd, int fdno, const char * fmode) { LZFILE *lzfile = lzopen_internal(fmode, fdno, 0); @@ -922,13 +936,13 @@ static FD_t lzdFdopen(FD_t fd, int fdno, const char * fmode) static int lzdFlush(FDSTACK_t fps) { - LZFILE *lzfile = fps->fp; + LZFILE *lzfile = lzdFp(fps); return fflush(lzfile->file); } static ssize_t lzdRead(FDSTACK_t fps, void * buf, size_t count) { - LZFILE *lzfile = fps->fp; + LZFILE *lzfile = lzdFp(fps); ssize_t rc = 0; if (lzfile) @@ -941,7 +955,7 @@ static ssize_t lzdRead(FDSTACK_t fps, void * buf, size_t count) static ssize_t lzdWrite(FDSTACK_t fps, const void * buf, size_t count) { - LZFILE *lzfile = fps->fp; + LZFILE *lzfile = lzdFp(fps); ssize_t rc = 0; rc = lzwrite(lzfile, (void *)buf, count); @@ -953,7 +967,7 @@ static ssize_t lzdWrite(FDSTACK_t fps, const void * buf, size_t count) static int lzdClose(FDSTACK_t fps) { - LZFILE *lzfile = fps->fp; + LZFILE *lzfile = lzdFp(fps); int rc; if (lzfile == NULL) return -2; @@ -1128,6 +1142,11 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode) return NULL; } +static rpmzstd zstdFp(FDSTACK_t fps) +{ + return (rpmzstd)fps->fp; +} + static FD_t zstdFdopen(FD_t fd, int fdno, const char * fmode) { rpmzstd zstd = rpmzstdNew(fdno, fmode); @@ -1142,7 +1161,7 @@ static FD_t zstdFdopen(FD_t fd, int fdno, const char * fmode) static int zstdFlush(FDSTACK_t fps) { - rpmzstd zstd = (rpmzstd) fps->fp; + rpmzstd zstd = zstdFp(fps); assert(zstd); int rc = -1; @@ -1174,7 +1193,7 @@ assert(zstd); static ssize_t zstdRead(FDSTACK_t fps, void * buf, size_t count) { - rpmzstd zstd = (rpmzstd) fps->fp; + rpmzstd zstd = zstdFp(fps); assert(zstd); ZSTD_outBuffer zob = { buf, count, 0 }; @@ -1200,7 +1219,7 @@ assert(zstd); static ssize_t zstdWrite(FDSTACK_t fps, const void * buf, size_t count) { - rpmzstd zstd = (rpmzstd) fps->fp; + rpmzstd zstd = zstdFp(fps); assert(zstd); ZSTD_inBuffer zib = { buf, count, 0 }; @@ -1232,7 +1251,7 @@ assert(zstd); static int zstdClose(FDSTACK_t fps) { - rpmzstd zstd = (rpmzstd) fps->fp; + rpmzstd zstd = zstdFp(fps); assert(zstd); int rc = -2; From 216816cdc04ac9ccf7303abdb4047ef8b231bde6 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 1 Mar 2024 10:46:16 +0200 Subject: [PATCH 15/17] Use an union for the zstd compress/decompress streams instead Cleaner than void pointer and avoid casting. --- rpmio/rpmio.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index f711e1272b..802cc671ea 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -1003,7 +1003,10 @@ typedef struct rpmzstd_s { int fdno; int level; /*!< compression level */ FILE * fp; - void * _stream; /*!< ZSTD_{C,D}Stream */ + union { + ZSTD_DStream *d; + ZSTD_CStream *c; + } stream; size_t nb; void * b; ZSTD_inBuffer zib; /*!< ZSTD_inBuffer */ @@ -1012,6 +1015,7 @@ typedef struct rpmzstd_s { static rpmzstd rpmzstdNew(int fdno, const char *fmode) { + rpmzstd zstd = NULL; int flags = 0; int level = 3; const char * s = fmode; @@ -1092,42 +1096,40 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode) if (fp == NULL) return NULL; - void * _stream = NULL; + zstd = (rpmzstd) xcalloc(1, sizeof(*zstd)); size_t nb = 0; if ((flags & O_ACCMODE) == O_RDONLY) { /* decompressing */ - if ((_stream = (void *) ZSTD_createDStream()) == NULL - || ZSTD_isError(ZSTD_initDStream(_stream))) { + if ((zstd->stream.d = ZSTD_createDStream()) == NULL + || ZSTD_isError(ZSTD_initDStream(zstd->stream.d))) { goto err; } nb = ZSTD_DStreamInSize(); } else { /* compressing */ - if ((_stream = (void *) ZSTD_createCCtx()) == NULL - || ZSTD_isError(ZSTD_CCtx_setParameter(_stream, ZSTD_c_compressionLevel, level))) { + if ((zstd->stream.c = ZSTD_createCCtx()) == NULL + || ZSTD_isError(ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_compressionLevel, level))) { goto err; } if (longdist) { - if (ZSTD_isError(ZSTD_CCtx_setParameter(_stream, ZSTD_c_enableLongDistanceMatching, longdist)) - || ZSTD_isError(ZSTD_CCtx_setParameter(_stream, ZSTD_c_windowLog, windowlog))) { + if (ZSTD_isError(ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_enableLongDistanceMatching, longdist)) + || ZSTD_isError(ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_windowLog, windowlog))) { goto err; } } if (threads > 0) { - if (ZSTD_isError (ZSTD_CCtx_setParameter(_stream, ZSTD_c_nbWorkers, threads))) + if (ZSTD_isError (ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_nbWorkers, threads))) rpmlog(RPMLOG_DEBUG, "zstd library does not support multi-threading\n"); } nb = ZSTD_CStreamOutSize(); } - rpmzstd zstd = (rpmzstd) xcalloc(1, sizeof(*zstd)); zstd->flags = flags; zstd->fdno = fdno; zstd->level = level; zstd->fp = fp; - zstd->_stream = _stream; zstd->nb = nb; zstd->b = xmalloc(nb); @@ -1136,9 +1138,9 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode) err: fclose(fp); if ((flags & O_ACCMODE) == O_RDONLY) - ZSTD_freeDStream(_stream); + ZSTD_freeDStream(zstd->stream.d); else - ZSTD_freeCCtx(_stream); + ZSTD_freeCCtx(zstd->stream.c); return NULL; } @@ -1175,7 +1177,7 @@ assert(zstd); zstd->zob.dst = zstd->b; zstd->zob.size = zstd->nb; zstd->zob.pos = 0; - xx = ZSTD_compressStream2(zstd->_stream, &zstd->zob, &zib, ZSTD_e_flush); + xx = ZSTD_compressStream2(zstd->stream.c, &zstd->zob, &zib, ZSTD_e_flush); if (ZSTD_isError(xx)) { fps->errcookie = ZSTD_getErrorName(xx); break; @@ -1208,7 +1210,7 @@ assert(zstd); } /* Decompress next chunk. */ - int xx = ZSTD_decompressStream(zstd->_stream, &zob, &zstd->zib); + int xx = ZSTD_decompressStream(zstd->stream.d, &zob, &zstd->zib); if (ZSTD_isError(xx)) { fps->errcookie = ZSTD_getErrorName(xx); return -1; @@ -1231,7 +1233,7 @@ assert(zstd); zstd->zob.pos = 0; /* Compress next chunk. */ - int xx = ZSTD_compressStream2(zstd->_stream, &zstd->zob, &zib, ZSTD_e_continue); + int xx = ZSTD_compressStream2(zstd->stream.c, &zstd->zob, &zib, ZSTD_e_continue); if (ZSTD_isError(xx)) { fps->errcookie = ZSTD_getErrorName(xx); return -1; @@ -1257,7 +1259,7 @@ assert(zstd); if ((zstd->flags & O_ACCMODE) == O_RDONLY) { /* decompressing */ rc = 0; - ZSTD_freeDStream(zstd->_stream); + ZSTD_freeDStream(zstd->stream.d); } else { /* compressing */ /* close frame */ int xx; @@ -1266,7 +1268,7 @@ assert(zstd); zstd->zob.dst = zstd->b; zstd->zob.size = zstd->nb; zstd->zob.pos = 0; - xx = ZSTD_compressStream2(zstd->_stream, &zstd->zob, &zib, ZSTD_e_end); + xx = ZSTD_compressStream2(zstd->stream.c, &zstd->zob, &zib, ZSTD_e_end); if (ZSTD_isError(xx)) { fps->errcookie = ZSTD_getErrorName(xx); break; @@ -1278,7 +1280,7 @@ assert(zstd); else rc = 0; } while (xx != 0); - ZSTD_freeCCtx(zstd->_stream); + ZSTD_freeCCtx(zstd->stream.c); } if (zstd->fp && fileno(zstd->fp) > 2) From 1f68fa055dc8bfbac753546a21435a49dd69d1c7 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 11:12:59 +0300 Subject: [PATCH 16/17] Avoid c++ reserved keywords new, class and namespace --- build/rpmfc.c | 18 +++++++++--------- lib/formats.c | 10 +++++----- tools/rpmsort.c | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/build/rpmfc.c b/build/rpmfc.c index 3b0400fef3..042a92d4a4 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -261,12 +261,12 @@ static int rpmfcExpandAppend(ARGV_t * argvp, ARGV_const_t av) } static rpmds rpmdsSingleNS(rpmstrPool pool, - rpmTagVal tagN, const char *namespace, + rpmTagVal tagN, const char *namespc, const char * N, const char * EVR, rpmsenseFlags Flags) { rpmds ds = NULL; - if (namespace) { - char *NSN = rpmExpand(namespace, "(", N, ")", NULL); + if (namespc) { + char *NSN = rpmExpand(namespc, "(", N, ")", NULL); ds = rpmdsSinglePool(pool, tagN, NSN, EVR, Flags); free(NSN); } else { @@ -594,7 +594,7 @@ static ARGV_t runCall(const char *name, const char *buildRoot, ARGV_t fns) struct addReqProvDataFc { rpmfc fc; - const char *namespace; + const char *namespc; regex_t *exclude; }; @@ -604,10 +604,10 @@ static rpmRC addReqProvFc(void *cbdata, rpmTagVal tagN, { struct addReqProvDataFc *data = cbdata; rpmfc fc = data->fc; - const char *namespace = data->namespace; + const char *namespc = data->namespc; regex_t *exclude = data->exclude; - rpmds ds = rpmdsSingleNS(fc->pool, tagN, namespace, N, EVR, Flags); + rpmds ds = rpmdsSingleNS(fc->pool, tagN, namespc, N, EVR, Flags); /* Add to package and file dependencies unless filtered */ if (regMatch(exclude, rpmdsDNEVR(ds)+2) == 0) rpmfcAddFileDep(&fc->fileDeps, ds, index); @@ -683,7 +683,7 @@ static int genDeps(const char *mname, int multifile, rpmTagVal tagN, static int rpmfcHelper(rpmfc fc, int *ixs, int n, const char *proto, const struct exclreg_s *excl, rpmsenseFlags dsContext, rpmTagVal tagN, - const char *namespace, const char *mname) + const char *namespc, const char *mname) { int rc = 0; const char **paths = xcalloc(n + 1, sizeof(*paths)); @@ -708,7 +708,7 @@ static int rpmfcHelper(rpmfc fc, int *ixs, int n, const char *proto, struct addReqProvDataFc data; data.fc = fc; - data.namespace = namespace; + data.namespc = namespc; data.exclude = excl->exclude; if (proto && rstreq(proto, "multifile")) { @@ -1116,7 +1116,7 @@ static int applyAttr(rpmfc fc, int aix, char *mname = rstrscat(NULL, "__", aname, "_", dep->name, NULL); if (rpmMacroIsDefined(NULL, mname)) { - char *ns = rpmfcAttrMacro(aname, "namespace", NULL); + char *ns = rpmfcAttrMacro(aname, "namespc", NULL); rc = rpmfcHelper(fc, ixs, n, attr->proto, excl, dep->type, dep->tag, ns, mname); free(ns); diff --git a/lib/formats.c b/lib/formats.c index 3e001c604e..4a80f9e329 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -32,13 +32,13 @@ typedef char * (*headerTagFormatFunction) (rpmtd td, char **emsg); struct headerFmt_s { rpmtdFormats fmt; /*!< Value of extension */ const char *name; /*!< Name of extension. */ - rpmTagClass class; /*!< Class of source data (RPM_ANY_CLASS for any) */ + rpmTagClass tclass; /*!< Class of source data (RPM_ANY_CLASS for any) */ headerTagFormatFunction func; /*!< Pointer to formatter function. */ }; -static const char *classEr(rpmTagClass class) +static const char *classEr(rpmTagClass tclass) { - switch (class) { + switch (tclass) { case RPM_BINARY_CLASS: return _("(not a blob)"); case RPM_NUMERIC_CLASS: return _("(not a number)"); case RPM_STRING_CLASS: return _("(not a string)"); @@ -652,8 +652,8 @@ char *rpmHeaderFormatCall(headerFmt fmt, rpmtd td) char *ret = NULL; char *err = NULL; - if (fmt->class != RPM_ANY_CLASS && rpmtdClass(td) != fmt->class) - err = xstrdup(classEr(fmt->class)); + if (fmt->tclass != RPM_ANY_CLASS && rpmtdClass(td) != fmt->tclass) + err = xstrdup(classEr(fmt->tclass)); else ret = fmt->func(td, &err); diff --git a/tools/rpmsort.c b/tools/rpmsort.c index 3ff874232a..c67ee9f59c 100644 --- a/tools/rpmsort.c +++ b/tools/rpmsort.c @@ -144,17 +144,17 @@ static void add_input(const char *filename, char ***package_names, while (input_buffer && *input_buffer && (position_of_newline = strchrnul(input_buffer, '\n'))) { size_t sz = position_of_newline - input_buffer; - char *new; + char *newl; if (sz == 0) { input_buffer = position_of_newline + 1; continue; } - new = rstrndup(input_buffer, sz); + newl = rstrndup(input_buffer, sz); names = xrealloc(names, sizeof(char *) * (n_names + 1)); - names[n_names] = new; + names[n_names] = newl; n_names++; /* Move buffer ahead to next line. */ From f40532127bb0003058d793ae217c0a56c741be8d Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 5 Apr 2024 11:09:38 +0300 Subject: [PATCH 17/17] readline callback const correctness --- rpmio/rpmlua.c | 2 +- rpmio/rpmlua.h | 2 +- tools/rpmlua.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c index fa64bee014..e63ab050d9 100644 --- a/rpmio/rpmlua.c +++ b/rpmio/rpmlua.c @@ -343,7 +343,7 @@ int rpmluaRunScriptFile(rpmlua lua, const char *filename) return ret; } -static char *lamereadline(char *prompt) +static char *lamereadline(const char *prompt) { static char buffer[1024]; if (prompt) { diff --git a/rpmio/rpmlua.h b/rpmio/rpmlua.h index 756388aa30..f8f92216d9 100644 --- a/rpmio/rpmlua.h +++ b/rpmio/rpmlua.h @@ -6,7 +6,7 @@ typedef struct rpmlua_s * rpmlua; struct rpmhookArgs_s; -typedef char * (*rpmluarl)(char *); +typedef char * (*rpmluarl)(const char *); #ifdef __cplusplus extern "C" { diff --git a/tools/rpmlua.c b/tools/rpmlua.c index 7738ab04dc..cdfcae9b78 100644 --- a/tools/rpmlua.c +++ b/tools/rpmlua.c @@ -33,7 +33,7 @@ static struct poptOption optionsTable[] = { }; #ifdef HAVE_READLINE -static char *myreadline(char *prompt) +static char *myreadline(const char *prompt) { char *line = readline(prompt); if (line && *line)