From: Michael Tremer Date: Sat, 10 Apr 2021 15:25:38 +0000 (+0000) Subject: Remove STRING_SIZE X-Git-Tag: 0.9.28~1285^2~377 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7500066cf17cce9ccb977b0b322b410bd9e56027;p=pakfire.git Remove STRING_SIZE Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/constants.h b/src/_pakfire/constants.h index fbf5832f4..8d5cbbc92 100644 --- a/src/_pakfire/constants.h +++ b/src/_pakfire/constants.h @@ -21,8 +21,6 @@ #ifndef PYTHON_PAKFIRE_CONSTANTS_H #define PYTHON_PAKFIRE_CONSTANTS_H -#define STRING_SIZE 2048 - /* Load all required modules for the translation. */ diff --git a/src/libpakfire/include/pakfire/constants.h b/src/libpakfire/include/pakfire/constants.h index 90296cb16..bdbb3f426 100644 --- a/src/libpakfire/include/pakfire/constants.h +++ b/src/libpakfire/include/pakfire/constants.h @@ -27,8 +27,6 @@ // Maximum length of an architecture name #define ARCH_MAX 16 -#define STRING_SIZE 1024 - #ifdef PAKFIRE_PRIVATE // The file format that this version generates diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 3c35862cb..a44ee8e8a 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -711,26 +711,13 @@ static void pakfire_package_dump_add_line(char** str, const char* key, const cha } static void pakfire_package_dump_add_lines(char** str, const char* key, const char* val) { - const char* string = val; - - while (*string) { - char line[STRING_SIZE]; - int counter = 0; - - while (*string) { - if (*string == '\n') { - string++; - break; - } - - line[counter++] = *string++; - } - line[counter] = '\0'; + char** lines = pakfire_split_string(val, '\n'); + if (!lines) + return; - if (*line) { - pakfire_package_dump_add_line(str, key, line); - key = NULL; - } + while (*lines) { + pakfire_package_dump_add_line(str, key, *lines); + lines++; } } @@ -738,8 +725,8 @@ static void pakfire_package_dump_add_line_date(char** str, const char* key, unsi // Convert from integer to tm struct. struct tm* timer = gmtime((time_t *)&date); - char val[STRING_SIZE]; - strftime(val, STRING_SIZE, "%a, %d %b %Y %T %z", timer); + char val[128]; + strftime(val, sizeof(val) - 1, "%a, %d %b %Y %T %z", timer); pakfire_package_dump_add_line(str, key, val); } diff --git a/src/libpakfire/problem.c b/src/libpakfire/problem.c index 0508285e3..ab435e934 100644 --- a/src/libpakfire/problem.c +++ b/src/libpakfire/problem.c @@ -54,93 +54,93 @@ static char* to_string(PakfireProblem problem) { SolverRuleinfo type = solver_ruleinfo(solver, rule, &source, &target, &dep); - char s[STRING_SIZE]; + char s[1024]; switch (type) { case SOLVER_RULE_DISTUPGRADE: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("%s does not belong to a distupgrade repository"), pool_solvid2str(pool, source) ); break; case SOLVER_RULE_INFARCH: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("%s has inferior architecture"), pool_solvid2str(pool, source) ); break; case SOLVER_RULE_UPDATE: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("problem with installed package %s"), pool_solvid2str(pool, source) ); break; case SOLVER_RULE_JOB: - snprintf(s, STRING_SIZE - 1, _("conflicting requests")); + snprintf(s, sizeof(s) - 1, _("conflicting requests")); break; case SOLVER_RULE_JOB_UNSUPPORTED: - snprintf(s, STRING_SIZE - 1, _("unsupported request")); + snprintf(s, sizeof(s) - 1, _("unsupported request")); break; case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("nothing provides requested %s"), pool_dep2str(pool, dep) ); break; case SOLVER_RULE_JOB_UNKNOWN_PACKAGE: - snprintf(s, STRING_SIZE - 1, _("package %s does not exist"), + snprintf(s, sizeof(s) - 1, _("package %s does not exist"), pool_dep2str(pool, dep) ); break; case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM: - snprintf(s, STRING_SIZE - 1, _("%s is provided by the system"), + snprintf(s, sizeof(s) - 1, _("%s is provided by the system"), pool_dep2str(pool, dep) ); break; case SOLVER_RULE_RPM: - snprintf(s, STRING_SIZE - 1, _("some dependency problem")); + snprintf(s, sizeof(s) - 1, _("some dependency problem")); break; case SOLVER_RULE_BEST: if (source > 0) - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("cannot install the best update candidate for package %s"), pool_solvid2str(pool, source) ); else - snprintf(s, STRING_SIZE - 1, _("cannot install the best candidate for the job")); + snprintf(s, sizeof(s) - 1, _("cannot install the best candidate for the job")); break; case SOLVER_RULE_RPM_NOT_INSTALLABLE: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("package %s is not installable"), pool_solvid2str(pool, source) ); break; case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("nothing provides %s needed by %s"), pool_dep2str(pool, dep), pool_solvid2str(pool, source) ); break; case SOLVER_RULE_RPM_SAME_NAME: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("cannot install both %s and %s"), pool_solvid2str(pool, source), pool_solvid2str(pool, target) ); break; case SOLVER_RULE_RPM_PACKAGE_CONFLICT: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("package %s conflicts with %s provided by %s"), pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target) @@ -148,7 +148,7 @@ static char* to_string(PakfireProblem problem) { break; case SOLVER_RULE_RPM_PACKAGE_OBSOLETES: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("package %s obsoletes %s provided by %s"), pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target) @@ -156,7 +156,7 @@ static char* to_string(PakfireProblem problem) { break; case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("installed package %s obsoletes %s provided by %s"), pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target) @@ -164,7 +164,7 @@ static char* to_string(PakfireProblem problem) { break; case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("package %s implicitely obsoletes %s provided by %s"), pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target) @@ -172,21 +172,21 @@ static char* to_string(PakfireProblem problem) { break; case SOLVER_RULE_RPM_PACKAGE_REQUIRES: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("package %s requires %s, but none of the providers can be installed"), pool_solvid2str(pool, source), pool_dep2str(pool, dep) ); break; case SOLVER_RULE_RPM_SELF_CONFLICT: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("package %s conflicts with %s provided by itself"), pool_solvid2str(pool, source), pool_dep2str(pool, dep) ); break; case SOLVER_RULE_YUMOBS: - snprintf(s, STRING_SIZE - 1, + snprintf(s, sizeof(s) - 1, _("both package %s and %s obsolete %s"), pool_solvid2str(pool, source), pool_solvid2str(pool, target), pool_dep2str(pool, dep) ); @@ -196,7 +196,7 @@ static char* to_string(PakfireProblem problem) { case SOLVER_RULE_FEATURE: case SOLVER_RULE_LEARNT: case SOLVER_RULE_CHOICE: - snprintf(s, STRING_SIZE - 1, _("bad rule type")); + snprintf(s, sizeof(s) - 1, _("bad rule type")); break; } diff --git a/src/libpakfire/solution.c b/src/libpakfire/solution.c index 8bef42d9c..2c56009bb 100644 --- a/src/libpakfire/solution.c +++ b/src/libpakfire/solution.c @@ -55,7 +55,7 @@ static void import_elements(PakfireSolution solution) { Id rp; Id element = 0; while ((element = solver_next_solutionelement(solver, pakfire_problem_get_id(solution->problem), solution->id, element, &p, &rp)) != 0) { - char line[STRING_SIZE]; + char line[1024]; if (p == SOLVER_SOLUTION_JOB || p == SOLVER_SOLUTION_POOLJOB) { if (p == SOLVER_SOLUTION_JOB) @@ -65,49 +65,49 @@ static void import_elements(PakfireSolution solution) { Id what = solver->job.elements[rp]; // XXX pool_job2str must be localised - snprintf(line, STRING_SIZE - 1, _("do not ask to %s"), + snprintf(line, sizeof(line) - 1, _("do not ask to %s"), pool_job2str(pool, how, what, 0)); } else if (p == SOLVER_SOLUTION_INFARCH) { Solvable* s = pool->solvables + rp; if (pool->installed && s->repo == pool->installed) - snprintf(line, STRING_SIZE - 1, _("keep %s despite the inferior architecture"), + snprintf(line, sizeof(line) - 1, _("keep %s despite the inferior architecture"), pool_solvable2str(pool, s)); else - snprintf(line, STRING_SIZE - 1, _("install %s despite the inferior architecture"), + snprintf(line, sizeof(line) - 1, _("install %s despite the inferior architecture"), pool_solvable2str(pool, s)); } else if (p == SOLVER_SOLUTION_DISTUPGRADE) { Solvable* s = pool->solvables + rp; if (pool->installed && s->repo == pool->installed) - snprintf(line, STRING_SIZE - 1, _("keep obsolete %s"), + snprintf(line, sizeof(line) - 1, _("keep obsolete %s"), pool_solvable2str(pool, s)); else - snprintf(line, STRING_SIZE - 1, _("install %s"), + snprintf(line, sizeof(line) - 1, _("install %s"), pool_solvable2str(pool, s)); } else if (p == SOLVER_SOLUTION_BEST) { Solvable* s = pool->solvables + rp; if (pool->installed && s->repo == pool->installed) - snprintf(line, STRING_SIZE - 1, _("keep old %s"), + snprintf(line, sizeof(line) - 1, _("keep old %s"), pool_solvable2str(pool, s)); else - snprintf(line, STRING_SIZE - 1, _("install %s despite the old version"), + snprintf(line, sizeof(line) - 1, _("install %s despite the old version"), pool_solvable2str(pool, s)); } else if (p > 0 && rp == 0) - snprintf(line, STRING_SIZE - 1, _("allow deinstallation of %s"), + snprintf(line, sizeof(line) - 1, _("allow deinstallation of %s"), pool_solvid2str(pool, p)); else if (p > 0 && rp > 0) - snprintf(line, STRING_SIZE - 1, _("allow replacement of %s with %s"), + snprintf(line, sizeof(line) - 1, _("allow replacement of %s with %s"), pool_solvid2str(pool, p), pool_solvid2str(pool, rp)); else - snprintf(line, STRING_SIZE - 1, _("bad solution element")); + snprintf(line, sizeof(line) - 1, _("bad solution element")); // Save line in elements array *elements++ = strdup(line); diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index e5a5154b1..d5b596a2c 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -227,7 +227,7 @@ char** pakfire_split_string(const char* s, char delim) { } char* pakfire_format_size(double size) { - char string[STRING_SIZE]; + char string[128]; const char* units[] = {" ", "k", "M", "G", "T", NULL}; const char** unit = units; @@ -236,7 +236,7 @@ char* pakfire_format_size(double size) { unit++; } - snprintf(string, STRING_SIZE, "%.0f%s", round(size), *unit); + snprintf(string, sizeof(string) - 1, "%.0f%s", round(size), *unit); return strdup(string); } @@ -244,10 +244,10 @@ char* pakfire_format_size(double size) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" static char* pakfire_strftime(const char* format, time_t t) { - char string[STRING_SIZE]; + char string[128]; struct tm* tm = gmtime(&t); - strftime(string, sizeof(string), format, tm); + strftime(string, sizeof(string) - 1, format, tm); return strdup(string); }