bin_PROGRAMS=vbig
vbig_SOURCES=vbig.cc Arcfour.h Arcfour.cc
man_MANS=vbig.1
-TESTS=t-both t-seeded t-separate t-corrupt t-truncated t-extended
+TESTS=t-both t-seeded t-separate t-corrupt t-truncated t-extended t-args
EXTRA_DIST=${man_MANS} README.md ${TESTS}
--- /dev/null
+#! /bin/sh
+set -e
+rm -f testoutput testexpect
+
+echo 'ERROR: invalid size: Numerical result out of range' > testexpect
+if ./vbig testfile 9223372036854775808 2>testoutput; then
+ echo >&2 ERROR: unexpectedly succeeded
+ exit 1
+fi
+diff -u testexpect testoutput
+
+echo 'ERROR: invalid size' > testexpect
+if ./vbig testfile 9007199254740992K 2>testoutput; then
+ echo >&2 ERROR: unexpectedly succeeded
+ exit 1
+fi
+diff -u testexpect testoutput
+
+if ./vbig testfile 8796093022208G 2>testoutput; then
+ echo >&2 ERROR: unexpectedly succeeded
+ exit 1
+fi
+diff -u testexpect testoutput
+
+echo 'ERROR: invalid scale' > testexpect
+if ./vbig testfile 1T 2>testoutput; then
+ echo >&2 ERROR: unexpectedly succeeded
+ exit 1
+fi
+diff -u testexpect testoutput
+
+if ./vbig testfile 1KK 2>testoutput; then
+ echo >&2 ERROR: unexpectedly succeeded
+ exit 1
+fi
+diff -u testexpect testoutput
+
+
+rm -f testoutput testexpect
#endif
}
+static void scale(int shift, long long &value) {
+ switch(shift) {
+ case 'K': shift = 10; break;
+ case 'M': shift = 20; break;
+ case 'G': shift = 30; break;
+ default: fatal(0, "invalid scale");
+ }
+ if(value > (LLONG_MAX >> shift))
+ fatal(0, "invalid size");
+ value <<= shift;
+}
+
static long long execute(mode_type mode, bool entire, const char *show);
static const char default_seed[] = "hexapodia as the key insight";
fatal(errno, "invalid size");
if(end == argv[1])
fatal(0, "invalid size");
- if(!strcmp(end, "K"))
- size <<= 10;
- else if(!strcmp(end, "M"))
- size <<= 20;
- else if(!strcmp(end, "G"))
- size <<= 30;
- else if(*end)
- fatal(0, "invalid size");
+ if(*end) {
+ if(end[1])
+ fatal(0, "invalid scale");
+ scale(*end, size);
+ }
} else if(entireopt) {
/* Use stupidly large size as a proxy for 'infinite' */
size = LLONG_MAX;