- cleanup code a bit
authorMichael Schroeder <mls@suse.de>
Thu, 6 Dec 2007 13:10:44 +0000 (13:10 +0000)
committerMichael Schroeder <mls@suse.de>
Thu, 6 Dec 2007 13:10:44 +0000 (13:10 +0000)
src/repo_solv.c
tools/repo_write.c

index edb5fcb..a7dcd57 100644 (file)
@@ -132,26 +132,31 @@ read_idarray(FILE *fp, Id max, Id *map, Id *store, Id *end, int relative)
       if ((c & 128) == 0)
        {
          x = (x << 6) | (c & 63);
-         if (!relative || x != 0)
+         if (relative)
            {
-             if (relative)
-               {
-                 x--;
-                 x += old;
-                 old = x;
-               }
-             if (x >= max)
+             if (x == 0 && c == 0x40)
                {
-                 pool_debug(mypool, SAT_FATAL, "read_idarray: id too large (%u/%u)\n", x, max);
-                 exit(1);
+                 /* prereq hack */
+                 if (store == end)
+                   {
+                     pool_debug(mypool, SAT_FATAL, "read_idarray: array overflow\n");
+                     exit(1);
+                   }
+                 *store++ = SOLVABLE_PREREQMARKER;
+                 old = 0;
+                 x = 0;
+                 continue;
                }
-             if (map)
-               x = map[x];
+             x = (x - 1) + old;
+             old = x;
+           }
+         if (x >= max)
+           {
+             pool_debug(mypool, SAT_FATAL, "read_idarray: id too large (%u/%u)\n", x, max);
+             exit(1);
            }
-         else
-           /* (relative && x==0) :
-              Ugly PREREQ handling.  See repo_write.c.  */
-           x = SOLVABLE_PREREQMARKER, old = 0;
+         if (map)
+           x = map[x];
          if (store == end)
            {
              pool_debug(mypool, SAT_FATAL, "read_idarray: array overflow\n");
@@ -160,6 +165,8 @@ read_idarray(FILE *fp, Id max, Id *map, Id *store, Id *end, int relative)
          *store++ = x;
          if ((c & 64) == 0)
            {
+             if (x == 0)       /* already have trailing zero? */
+               return store;
              if (store == end)
                {
                  pool_debug(mypool, SAT_FATAL, "read_idarray: array overflow\n");
index af7bf6c..11eb7a9 100644 (file)
@@ -198,8 +198,6 @@ write_idarray(FILE *fp, Pool *pool, NeedId *needid, Id *ids)
     return;
   if (!*ids)
     {
-      /* XXX I think this is broken.  A lone '0' will be interpreted as
-        zero plus end-of-array, which stores another zero.  */
       write_u8(fp, 0);
       return;
     }
@@ -235,8 +233,6 @@ write_idarray_sort(FILE *fp, Pool *pool, NeedId *needid, Id *ids)
     return;
   if (!*ids)
     {
-      /* XXX I think this is broken.  A lone '0' will be interpreted as
-        zero plus end-of-array, which stores another zero.  */
       write_u8 (fp, 0);
       return;
     }