chiark / gitweb /
Use shifts rather than multiplies to scale up size requests.
[vbig.git] / vbig.cc
diff --git a/vbig.cc b/vbig.cc
index 2a94519c590db01ed9ef1c84367bb829cc1ab7c2..86e24bf45d26d2f35689733ffdf3d9095fcd7e14 100644 (file)
--- a/vbig.cc
+++ b/vbig.cc
@@ -215,11 +215,11 @@ int main(int argc, char **argv) {
     if(end == argv[1])
       fatal(0, "invalid size");
     if(!strcmp(end, "K"))
-      size *= 1024;
+      size <<= 10;
     else if(!strcmp(end, "M"))
-      size *= 1024 * 1024;
+      size <<= 20;
     else if(!strcmp(end, "G"))
-      size *= 1024 * 1024 * 1024;
+      size <<= 30;
     else if(*end)
       fatal(0, "invalid size");
   } else if(entireopt) {
@@ -278,7 +278,7 @@ static void showprogress(long long amount, const char *show) {
 
 // write/verify the target file
 static long long execute(mode_type mode, bool entire, const char *show) {
-  Arcfour rng((const char*)seed, seedlen);
+  Arcfour rng((const uint8_t *)seed, seedlen);
   FILE *fp = fopen(path, mode == VERIFY ? "rb" : "wb");
   if(!fp)
     fatal(errno, "%s", path);
@@ -286,7 +286,7 @@ static long long execute(mode_type mode, bool entire, const char *show) {
     flushCache(fp);
   if(mode == CREATE && entire)
     setvbuf(fp, 0, _IONBF, 0);
-  char generated[4096], input[4096];
+  uint8_t generated[4096], input[4096];
   long long remain = size;
   static const size_t rc4drop = 3072; // en.wikipedia.org/wiki/RC4#Security
   assert(rc4drop <= sizeof(generated));
@@ -312,7 +312,7 @@ static long long execute(mode_type mode, bool entire, const char *show) {
       if(memcmp(generated, input, bytesRead)) {
         for(size_t n = 0; n < bytesRead; ++n)
           if(generated[n] != input[n])
-            fatal(0, "%s corrupted at %lld/%lld bytes (expected %d got %d)",
+            fatal(0, "%s: corrupted at %lld/%lld bytes (expected %d got %d)",
                     path, size - remain + n, size,
                     (unsigned char)generated[n], (unsigned char)input[n]);
       }