summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2019-06-19 23:32:32 +1000
committerDamien Zammit <damien@zamaudio.com>2019-06-19 23:32:32 +1000
commit8d46a829da18cec9a35def473a89062991bc3d4b (patch)
treea31b5c86ef3988dc36d64000bc7545703237746c
parentc086bf3a63540e4dfa9732edbe4596836441cad6 (diff)
Fix uninitialised value bug - thanks Robin!
-rw-r--r--ptfformat.cc21
-rw-r--r--ptftool.cc14
-rw-r--r--tests.sh1
3 files changed, 26 insertions, 10 deletions
diff --git a/ptfformat.cc b/ptfformat.cc
index 669a801..0bacca0 100644
--- a/ptfformat.cc
+++ b/ptfformat.cc
@@ -437,15 +437,18 @@ PTFFormat::load(std::string ptf, int64_t targetsr) {
return -1;
if (parse_version())
- return -1;
+ return -2;
if (version < 5 || version > 12)
- return -1;
+ return -3;
targetrate = targetsr;
- if (parse())
- return -1;
+ int err = 0;
+ if ((err = parse())) {
+ printf ("PARSE FAILED %d\n", err);
+ return -4;
+ }
return 0;
}
@@ -557,7 +560,7 @@ PTFFormat::setrates(void) {
bool
PTFFormat::parse_block_at(uint32_t pos, struct block_t *block, int level) {
struct block_t b;
- int childjump;
+ int childjump = 0;
uint32_t i;
if (pos + 7 > len)
@@ -644,13 +647,13 @@ PTFFormat::parse(void) {
return -1;
setrates();
if (sessionrate < 44100 || sessionrate > 192000)
- return -1;
+ return -2;
if (!parseaudio())
- return -1;
+ return -3;
if (!parserest())
- return -1;
+ return -4;
if (!parsemidi())
- return -1;
+ return -5;
return 0;
}
diff --git a/ptftool.cc b/ptftool.cc
index 89827c7..95da0ab 100644
--- a/ptftool.cc
+++ b/ptftool.cc
@@ -41,7 +41,19 @@ int main (int argc, char **argv) {
switch (ok) {
default:
case -1:
- printf("Cannot open ptf, quit\n");
+ printf("Cannot decrypt ptf, quit\n");
+ exit(-1);
+ break;
+ case -2:
+ printf("Cannot extract version from ptf, quit\n");
+ exit(-1);
+ break;
+ case -3:
+ printf("Unsupported ptf version, quit\n");
+ exit(-1);
+ break;
+ case -4:
+ printf("Cannot parse ptf, quit\n");
exit(-1);
break;
case 0:
diff --git a/tests.sh b/tests.sh
index b6e25e0..39306ec 100644
--- a/tests.sh
+++ b/tests.sh
@@ -28,6 +28,7 @@ run_test() {
fi
TMP1=$(mktemp)
TMP2=$(mktemp)
+ echo "$PTFTOOL $FILE"
$PTFTOOL $FILE > $TMP1
echo "$EXPECT" > $TMP2
DIFFED=$($DIFF -U0 $TMP2 $TMP1 | $GREP -v -E '^\+\+\+ |^--- ')