Skip to content

Commit

Permalink
make sure that output is on paragraph boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
tsupplis committed Sep 30, 2021
1 parent 809d49c commit b1e351e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bin2cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int main_alt(argc, argv)
FILE *fin, *fout;
long pos, paras, maxsize;
int c;
int rest=0;

if (argc < 3) {
fprintf(stderr,"ERR: Invalid command line\n");
Expand Down Expand Up @@ -79,6 +80,7 @@ int main_alt(argc, argv)
/* Calculate size in paragraphs. Add 16 paragraphs for the
* Zero Page. */
paras = (pos + 15) / 16 + 0x10;
rest=(paras-1)*16-pos;

/* The CP/M-86 CMD format does not allow groups larger than 1M */
if (paras > 0xFFFF) {
Expand Down Expand Up @@ -128,6 +130,15 @@ int main_alt(argc, argv)
return 1;
}
}
while(rest--) {
if (fputc(0, fout) == EOF) {
fprintf(stderr,"ERR: Can't write content to output (%d)\n",errno);
fclose(fout);
unlink(argv[2]);
fclose(fin);
return 1;
}
}
if (fclose(fout)) {
fprintf(stderr,"ERR: Can't close output properly (%d)\n",errno);
unlink(argv[2]);
Expand Down

0 comments on commit b1e351e

Please sign in to comment.