From 59de645bcbc02f4044a697bbcc3a2a2a8523975f Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 24 May 2024 04:33:33 -0400 Subject: unprotbas: error if protecting vars but there are none, or protecting code but there is none. --- unprotbas.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'unprotbas.c') diff --git a/unprotbas.c b/unprotbas.c index 14fdc63..686b8c3 100644 --- a/unprotbas.c +++ b/unprotbas.c @@ -238,9 +238,13 @@ void breakcode(void) { } } - data[oldpos + 2] = 0; - if(verbose) - fprintf(stderr, "set invalid line length 0 at line %d, file offset %04x\n", lineno, oldpos + 2); + if(!oldpos) { + die("can't protect code because there are no lines of code"); + } else { + data[oldpos + 2] = 0; + if(verbose) + fprintf(stderr, "set invalid line length 0 at line %d, file offset %04x\n", lineno, oldpos + 2); + } } /* sometimes the variable name table isn't large enough to hold @@ -581,8 +585,13 @@ void scramble_vars(void) { for(i = vnstart; i < vvstart - 1; i++) data[i] = '\x9b'; - if(verbose) - fprintf(stderr, "replaced %d byte variable name table with EOLs.\n", i); + if(verbose) { + i -= vnstart; + if(i) + fprintf(stderr, "replaced %d byte variable name table with EOLs.\n", i); + else + die("can't protect variables because there are no variables."); + } } void print_help(void) { -- cgit v1.2.3