]> git.ipfire.org Git - pakfire.git/commitdiff
Remove STRING_SIZE
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 10 Apr 2021 15:25:38 +0000 (15:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 10 Apr 2021 15:25:38 +0000 (15:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/constants.h
src/libpakfire/include/pakfire/constants.h
src/libpakfire/package.c
src/libpakfire/problem.c
src/libpakfire/solution.c
src/libpakfire/util.c

index fbf5832f4580372e76ae9712efeb898f3f0f1b1b..8d5cbbc92d8939783846158c457dc4d41583fefd 100644 (file)
@@ -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.
 */
index 90296cb166d182553242d0c2a56b5b81a51ede15..bdbb3f4262d852a1cfc6a1090e9a744995c2282f 100644 (file)
@@ -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
index 3c35862cb5dba92a65aac7bd0d42e08194e1de83..a44ee8e8a3d2db7783e082e69194c2c13b7c4bb7 100644 (file)
@@ -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);
 }
index 0508285e35f039bcebc89a70c39d08701ed0774a..ab435e9343689e4854af4ffbdd79564ed7c78f3e 100644 (file)
@@ -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;
 
        }
index 8bef42d9c98b8950209af17563f1c8d447dac256..2c56009bbdb79eaefff2365054b8fbaaa29084f7 100644 (file)
@@ -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);
index e5a5154b10dee00da83a2734ad9a5e0567b1cd11..d5b596a2c5c99ba172086da3bd88b3e26d133f2b 100644 (file)
@@ -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);
 }