Skip to content

Commit

Permalink
More memory safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Stvff committed Mar 18, 2022
1 parent 2ec5394 commit b963dd1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $ aasm <script> <options>
|`-i <statement>`|Executes the designated statement. This statement can not contain spaces.|
|`-e` |Exit immediately after executing the statement that was passed as argument of -i.|
|`-l <statefile>`|Loads the designated statefile before interpreting any statements.|
|`-b` |Sets the notation to big endian before doing anything else.|
|`-b` |Sets the notation to big endian before interpreting any statements.|
|`-v` |Displays the name, version and libraries.|
|`-h` |Prints this table.|
|`**************`||
Expand Down
18 changes: 16 additions & 2 deletions aasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ int executehandler_main(GLOBAL* mainptrs){
int update_main(GLOBAL* mainptrs){
free(mainptrs->userInput);
mainptrs->userInput = (char*) malloc((mainptrs->userInputLen + maxKeywordLen)*sizeof(char));
mainptrs->userInput[0] = '\0';

if(mainptrs->debug == 'v') printf("main updated\n");
return 1;
Expand Down Expand Up @@ -182,7 +183,7 @@ int handlecommandlineargs(int argc, char* argv[], GLOBAL* mainptrs){
printf(" -i <statement> Executes the designated statement. This statement can not contain spaces.\n");
printf(" -e Exit immediately after executing the statement that was passed as an argument of -i.\n");
printf(" -l <statefile> Loads the designated statefile before interpreting any statements.\n");
printf(" -b Sets the notation to big endian before doing anything else.\n");
printf(" -b Sets the notation to big endian before interpreting any statements.\n");
printf(" -v Displays the name, version and libraries.\n");
printf(" -h Look ma! I'm on TV!\n");
mainptrs->inputMode = 'w';
Expand Down Expand Up @@ -220,7 +221,7 @@ int dothing(GLOBAL* mainptrs){
while (mainptrs->lookingMode != 'd' && entry != '\0' && entry != '\n' && entry != '\r' && entry != ';')
{
entry = mainptrs->userInput[mainptrs->readhead];
if(mainptrs->debug == 'v') printf("entry: %c\n", entry);
if(mainptrs->debug == 'v') printf("On position %d, entry: %c\n", mainptrs->readhead, entry);

if(entry != ' ' && entry != '\t' && entry != '\0' && entry != '\n' && entry != '\r' && entry != ';'){
// functions
Expand Down Expand Up @@ -256,6 +257,15 @@ int dothing(GLOBAL* mainptrs){
}
}
mainptrs->readhead++;
if(mainptrs->readhead >= mainptrs->userInputLen){
printf("The statement on line %d ", mainptrs->flist[mainptrs->fileNr].lineNr);
if(mainptrs->inputMode == 'f'){
printf("in file %d ", mainptrs->fileNr);
}
printf("is too long (maximum is %u characters).\nIt is possible to change the maximum by modifying the `inplen` register.\n", mainptrs->userInputLen);
mainptrs->lookingMode = 'd';
mainptrs->inputMode = 'W';
}
}

if(mainptrs->lookingMode != 'd') executehandlers[mainptrs->libNr](mainptrs);
Expand All @@ -273,6 +283,7 @@ int getuserInput(GLOBAL* mainptrs){
case 'i':
printf("\\\\\\ ");
fgets(mainptrs->userInput, mainptrs->userInputLen, thefile->fp);
mainptrs->userInput[mainptrs->userInputLen] = '\0';
break;

case 'F':
Expand All @@ -296,9 +307,12 @@ int getuserInput(GLOBAL* mainptrs){
if(mainptrs->fileNr == 0) mainptrs->inputMode = 'i';
}
}
mainptrs->userInput[mainptrs->userInputLen] = '\0';
break;

case 'W':
fgets(mainptrs->userInput, mainptrs->userInputLen, thefile->fp);
mainptrs->userInput[0] = '\0';
case 'w':
mainptrs->inputMode = 'i';
break;
Expand Down
2 changes: 1 addition & 1 deletion scripts/rule110/ruleconv.aa
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set gr3, 00111110 ; 0: 000, 1: 100, 2: 010, 3: 110, 4: 001, 5: 101, 6: 011, 7: 1
dget gr3, gr1
cmp gr3, 0
Cg sprint "# "
Ce sprint ". "
Ce sprint " "
dset gr4, ir, gr3

inc ir
Expand Down

0 comments on commit b963dd1

Please sign in to comment.