libopkg: fix replacelist parsing and writing
authorJo-Philipp Wich <jo@mein.io>
Thu, 17 Jan 2019 21:02:37 +0000 (22:02 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 17 Jan 2019 21:02:37 +0000 (22:02 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/pkg.c
libopkg/pkg_depends.c

index 21f239eeab9514e2b58e3b3ff066a3c199d6cf36..e5bfe6f61b67583c00e528fb381162ace308dc13 100644 (file)
@@ -817,11 +817,11 @@ void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)
        case 'R':
                if (strcasecmp(field, "Replaces") == 0) {
                        ab_pkg = pkg_get_ptr(pkg, PKG_REPLACES);
-                       if (ab_pkg && *ab_pkg) {
+                       if (ab_pkg && ab_pkg[0]) {
                                fprintf(fp, "Replaces:");
-                               for (i = 0; *ab_pkg; i++, ab_pkg++) {
+                               for (i = 0; ab_pkg[i]; i++) {
                                        fprintf(fp, "%s %s", i == 0 ? "" : ",",
-                                               (*ab_pkg)->name);
+                                               ab_pkg[i]->name);
                                }
                                fprintf(fp, "\n");
                        }
index 748b5999393e6627ac5df5b3dcbf5aa2456618d9..ae2ac9baaebb962d9bf93ef8fa6a8c268062de73 100644 (file)
@@ -668,9 +668,8 @@ void parse_replacelist(pkg_t *pkg, char *list)
 
        abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
 
-       for (count = 1, item = strtok_r(list, ", ", &tok);
-            item;
-            count++, item = strtok_r(NULL, ", ", &tok), count++) {
+       for (count = 1, item = strtok_r(list, ", ", &tok); item;
+            count++, item = strtok_r(NULL, ", ", &tok)) {
                tmp = realloc(replaces, sizeof(abstract_pkg_t *) * (count + 1));
 
                if (!tmp)