]> mj.ucw.cz Git - libucw.git/commitdiff
interface of lizard_decompress_safe() has been simplified
authorRobert Spalek <robert@ucw.cz>
Mon, 28 Jun 2004 12:13:29 +0000 (12:13 +0000)
committerRobert Spalek <robert@ucw.cz>
Mon, 28 Jun 2004 12:13:29 +0000 (12:13 +0000)
lib/buck2obj.c
lib/lizard-safe.c
lib/lizard-test.c
lib/lizard.h

index ba7efd57a143211ca6f98e00e410088c9685ee2c..f268e11a0e5c7772aa9af3d984401c0560e94ef7 100644 (file)
@@ -141,15 +141,9 @@ obj_read_bucket(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fa
     {
       len = GET_U32(ptr);
       ptr += 4;
-      int res;
-      byte *new_ptr;
-      res = lizard_decompress_safe(ptr, buf->lizard, len, &new_ptr);
-      if (res != (int) len)
-      {
-       if (res >= 0)
-         errno = EINVAL;
+      byte *new_ptr = lizard_decompress_safe(ptr, buf->lizard, len);
+      if (!new_ptr)
        return NULL;
-      }
       ptr = new_ptr;
       end = ptr + len;
     }
index 9c347bd2d8f1d6f2bf7511f14849850f1325b679..88e9aebd4fc8070a1a97e239d487b8fd8a1b6963 100644 (file)
@@ -71,8 +71,8 @@ sigsegv_handler(int signal UNUSED)
   return 1;
 }
 
-int
-lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length, byte **ptr)
+byte *
+lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length)
   /* Decompresses in into buf, sets *ptr to the data, and returns the
    * uncompressed length.  If an error has occured, -1 is returned and errno is
    * set.  The buffer buf is automatically reallocated.  SIGSEGV is caught in
@@ -84,18 +84,22 @@ lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length,
     lizard_realloc(buf, lock_offset);
   volatile sh_sighandler_t old_handler = signal_handler[SIGSEGV];
   signal_handler[SIGSEGV] = sigsegv_handler;
-  int len;
+  byte *ptr;
   if (!setjmp(safe_decompress_jump))
   {
-    *ptr = buf->ptr + buf->len - lock_offset;
-    len = lizard_decompress(in, *ptr);
+    ptr = buf->ptr + buf->len - lock_offset;
+    int len = lizard_decompress(in, ptr);
+    if (len != (int) expected_length)
+    {
+      ptr = NULL;
+      errno = EINVAL;
+    }
   }
   else
   {
-    *ptr = NULL;
-    len = -1;
+    ptr = NULL;
     errno = EFAULT;
   }
   signal_handler[SIGSEGV] = old_handler;
-  return len;
+  return ptr;
 }
index 6ab7d8d007cf61d861088ca654880c661fc3fd1a..ba78e022cadd28ac52d404c31e45a921dab0f302 100644 (file)
@@ -101,13 +101,10 @@ main(int argc, char **argv)
     else
       smaller_li = 0;
     struct lizard_buffer *buf = lizard_alloc();
-    byte *ptr;
-    int lv = lizard_decompress_safe(mo, buf, crash ? smaller_li : li, &ptr);
-    printf("-> %d ", lv);
-    fflush(stdout);
-    if (lv < 0)
-      printf("err:%m ");
-    else if (lv != li || memcmp(mi, ptr, li))
+    byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li);
+    if (!ptr)
+      printf("err: %m");
+    else if (memcmp(mi, ptr, li))
       printf("WRONG");
     else
       printf("OK");
index bbd2a838a628928cd735570bf91169e1e47d69af..f81ea5f40777b3643021614119399a090074b98f 100644 (file)
@@ -32,4 +32,4 @@ struct lizard_buffer;
 
 struct lizard_buffer *lizard_alloc(void);
 void lizard_free(struct lizard_buffer *buf);
-int lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length, byte **ptr);
+byte *lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length);