Skip to content

Commit

Permalink
Merge pull request #516 from sneakywumpus/dev
Browse files Browse the repository at this point in the history
clang 19 static analyzer run & clean-up
  • Loading branch information
udo-munk authored Jan 16, 2025
2 parents 471bffa + 4dafe0f commit 635f663
Show file tree
Hide file tree
Showing 24 changed files with 318 additions and 294 deletions.
4 changes: 2 additions & 2 deletions altairsim/srcsim/simcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void config(void)
}

if ((fp = fopen(fn, "r")) != NULL) {
s = buf;
while (fgets(s, BUFSIZE, fp) != NULL) {
while (fgets(buf, BUFSIZE, fp) != NULL) {
s = buf;
if ((*s == '\n') || (*s == '\r') || (*s == '#'))
continue;
if ((t1 = strtok(s, " \t")) == NULL) {
Expand Down
18 changes: 9 additions & 9 deletions cpmsim/srcsim/simio.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ static void net_server_config(void)
char *s;
char fn[MAX_LFN];

strcpy(&fn[0], &confdir[0]);
strcat(&fn[0], "/net_server.conf");
strcpy(fn, confdir);
strcat(fn, "/net_server.conf");

if ((fp = fopen(fn, "r")) != NULL) {
LOG(TAG, "Server network configuration:\r\n");
s = &buf[0];
while (fgets(s, BUFSIZE, fp) != NULL) {
while (fgets(buf, BUFSIZE, fp) != NULL) {
s = buf;
if ((*s == '\n') || (*s == '#'))
continue;
i = atoi(s);
Expand Down Expand Up @@ -578,20 +578,20 @@ static void net_client_config(void)
char *s, *d;
char fn[MAX_LFN];

strcpy(&fn[0], &confdir[0]);
strcat(&fn[0], "/net_client.conf");
strcpy(fn, confdir);
strcat(fn, "/net_client.conf");

if ((fp = fopen(fn, "r")) != NULL) {
LOG(TAG, "Client network configuration:\r\n");
s = &buf[0];
while (fgets(s, BUFSIZE, fp) != NULL) {
while (fgets(buf, BUFSIZE, fp) != NULL) {
s = buf;
if ((*s == '\n') || (*s == '#'))
continue;
while ((*s != ' ') && (*s != '\t'))
s++;
while ((*s == ' ') || (*s == '\t'))
s++;
d = &cs_host[0];
d = cs_host;
while ((*s != ' ') && (*s != '\t'))
*d++ = *s++;
*d = '\0';
Expand Down
13 changes: 7 additions & 6 deletions cpmsim/srcsim/simmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ static inline BYTE memrdr(WORD addr)
}
#endif

if (selbnk == 0)
data = *(memory[0] + addr);

if (addr >= segsize)
if (selbnk == 0) {
data = *(memory[0] + addr);
else
data = *(memory[selbnk] + addr);
} else {
if (addr >= segsize)
data = *(memory[0] + addr);
else
data = *(memory[selbnk] + addr);
}

#ifdef BUS_8080
cpu_bus &= ~CPU_M1;
Expand Down
295 changes: 153 additions & 142 deletions cpmsim/srctools/bin2hex.c
Original file line number Diff line number Diff line change
@@ -1,161 +1,172 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>

void help(char *name)
{
printf("%s - BINARY to Intel HEX file convertor version 1.00\n"\
"(c)BCL Vysoke Myto 2001 (benedikt@lphard.cz)\n\n",name);
printf("Usage: %s [-option] binfile hexfile\n"\
" -l Bytes to read from binary file\n"\
" -i Binary file starting offset\n"\
" -o Output file offset (where HEX data starts)\n"\
" -t Exclude EOF record\n"\
" -a Append to end of existing HEX file\n"\
" -q Quiet mode (no statistics are printed)\n", name);
printf("%s - BINARY to Intel HEX file convertor version 1.00\n"
"(c)BCL Vysoke Myto 2001 (benedikt@lphard.cz)\n\n", name);
printf("Usage: %s [-option] binfile hexfile\n"
" -l Bytes to read from binary file\n"
" -i Binary file starting offset\n"
" -o Output file offset (where HEX data starts)\n"
" -t Exclude EOF record\n"
" -a Append to end of existing HEX file\n"
" -q Quiet mode (no statistics are printed)\n", name);
}

int main(int argc,char *argv[])/*Main routine*/
int main(int argc, char *argv[]) /* Main routine */
{
char *ifile = NULL;
char *ofile = NULL;
int c;
FILE *inp, *outp;
int ch,csum;
int ofsa = 0;
int cnt = 0;
struct stat statbuf;
long int foffset = 0;
long int fsize = 0;
long int fsub;
long int fpoint = 0;
long int adrs = 0;
unsigned char quiet = 0;
unsigned char eofrec = 0;
unsigned char append = 0;
char *ifile = NULL;
char *ofile = NULL;
int c;
FILE *inp, *outp;
int ch, csum;
int ofsa = 0;
int cnt = 0;
struct stat statbuf;
long foffset = 0;
long fsize = 0;
long fsub;
long fpoint = 0;
long adrs = 0;
unsigned char quiet = 0;
unsigned char eofrec = 0;
unsigned char append = 0;

opterr = 0; //print error message if unknown option
opterr = 0; //print error message if unknown option

while ((c = getopt (argc, argv, "l:i:o:taqv")) != -1)
switch (c) {
case 'l':
fsize = atol(optarg);
break;
case 'i':
foffset = atol(optarg);
break;
case 'o':
adrs = atol(optarg);
break;
case 't':
eofrec = 1;
break;
case 'a':
append = 1;
break;
case 'q':
quiet = 1;
break;
case 'v':
printf("%s - BINARY to Intel HEX file convertor version 1.00\n"\
"(c)BCL Vysoke Myto 2001 (benedikt@lphard.cz)\n",argv[0]);
return EXIT_SUCCESS;
case '?':
help (argv[0]);
return EXIT_FAILURE;
}
while ((c = getopt(argc, argv, "l:i:o:taqv")) != -1)
switch (c) {
case 'l':
fsize = atol(optarg);
break;
case 'i':
foffset = atol(optarg);
break;
case 'o':
adrs = atol(optarg);
break;
case 't':
eofrec = 1;
break;
case 'a':
append = 1;
break;
case 'q':
quiet = 1;
break;
case 'v':
printf("%s - BINARY to Intel HEX file convertor version 1.00\n"
"(c)BCL Vysoke Myto 2001 (benedikt@lphard.cz)\n", argv[0]);
return EXIT_SUCCESS;
case '?':
help(argv[0]);
return EXIT_FAILURE;
}

if ((argc - optind) != 2) {
printf("ERROR: Missing input/output file.\n");
help(argv[0]);
return EXIT_FAILURE;
}
ifile = argv[optind];
ofile = argv[optind+1];
if ((argc - optind) != 2) {
printf("ERROR: Missing input/output file.\n");
help(argv[0]);
return EXIT_FAILURE;
}
ifile = argv[optind];
ofile = argv[optind + 1];

/*Open file check*/
if((inp = fopen(ifile, "rb")) == NULL){
printf("ERROR: Cannot open input file.\n");
return EXIT_FAILURE;
}
fseek (inp, foffset, SEEK_SET);
/* Open file check */
if ((inp = fopen(ifile, "rb")) == NULL) {
printf("ERROR: Cannot open input file.\n");
return EXIT_FAILURE;
}
fseek(inp, foffset, SEEK_SET);

if (append == 0) {
if((outp = fopen(ofile, "wt")) == NULL){
printf("ERROR: Cannot open output file.\n");
return EXIT_FAILURE;
}
} else {
if((outp = fopen(ofile, "at")) == NULL){
printf("ERROR: Cannot re-open output file.\n");
return EXIT_FAILURE;
}
fseek (outp, 0, SEEK_END);
}
if (append == 0) {
if ((outp = fopen(ofile, "wt")) == NULL) {
fclose(inp);
printf("ERROR: Cannot open output file.\n");
return EXIT_FAILURE;
}
} else {
if ((outp = fopen(ofile, "at")) == NULL) {
fclose(inp);
printf("ERROR: Cannot re-open output file.\n");
return EXIT_FAILURE;
}
fseek(outp, 0, SEEK_END);
}

fstat(fileno(inp), &statbuf);
if (quiet == 0) printf("Input file size=%ld\n",(long)statbuf.st_size);
if (foffset > statbuf.st_size) {
printf("ERROR: Input offset > input file length\n");
}
if ((fsize == 0) || (fsize > (statbuf.st_size - foffset)))
fsize = statbuf.st_size - foffset;
fstat(fileno(inp), &statbuf);
if (quiet == 0)
printf("Input file size=%ld\n", (long) statbuf.st_size);
if (foffset > statbuf.st_size)
printf("ERROR: Input offset > input file length\n");
if (fsize == 0 || fsize > (statbuf.st_size - foffset))
fsize = statbuf.st_size - foffset;

// fprintf(outp,":020000020000FC\n");/*Start Header*/
fsub = fsize - fpoint;
if (fsub > 0x20) {
fprintf(outp,":20%04X00",(unsigned int) adrs); /*Hex line Header*/
csum = 0x20 + (adrs>>8) + (adrs & 0xFF);
adrs += 0x20;
}
else {
fprintf(outp, ":%02X%04X00", (unsigned int) fsub, (unsigned int) adrs);/*Hex line Header*/
csum = fsub + (adrs>>8) + (adrs & 0xFF);
adrs += fsub;
}
while (fsub > 0){
ch = fgetc(inp);
fprintf(outp,"%02X",ch); /*Put data*/
cnt++; fpoint++;
fsub = fsize - fpoint;
csum = ch + csum;
if((fsub == 0)||(cnt == 0x20)){
cnt = 0; csum = 0xFF & (~csum + 1);
fprintf(outp,"%02X\n",csum); /*Put checksum*/
if(fsub == 0) break;
if(adrs > 0xFFFF){
ofsa = 0x1000 + ofsa;
adrs = 0;
fprintf(outp,":02000002%04X",ofsa); /*Change offset address*/
csum = 0x02 + 0x02 + (ofsa>>8) + (ofsa & 0xFF);
csum = 0xFF & (~csum + 1);
fprintf(outp,"%02X\n", csum);
}
adrs = 0xFFFF & adrs;
if (fsub > 0x20) {
fprintf(outp,":20%04X00", (unsigned int) adrs); /*Next Hex line Header*/
csum = 0x20 + (adrs>>8) + (adrs & 0xFF);
adrs += 0x20;
}
else {
if(fsub > 0){
fprintf(outp, ":%02X%04X00", (unsigned int) fsub, (unsigned int) adrs); /*Next Hex line Header*/
csum = fsub + (adrs>>8) + (adrs & 0xFF);
adrs += fsub;
}
}
}
}
if (eofrec == 0) fprintf(outp,":00000001FF\n"); /*End footer*/
fflush (outp);
// fprintf(outp, ":020000020000FC\n"); /* Start Header */
fsub = fsize - fpoint;
if (fsub > 0x20) {
fprintf(outp, ":20%04X00", (unsigned) adrs); /* Hex line Header */
csum = 0x20 + (adrs >> 8) + (adrs & 0xFF);
adrs += 0x20;
} else {
fprintf(outp, ":%02X%04X00", (unsigned) fsub,
(unsigned) adrs); /* Hex line Header */
csum = fsub + (adrs >> 8) + (adrs & 0xFF);
adrs += fsub;
}
while (fsub > 0) {
if ((ch = fgetc(inp)) == EOF) {
fclose(inp);
fclose(outp);
printf("ERROR: Cannot read from input file.\n");
return EXIT_FAILURE;
}
fprintf(outp, "%02X", ch); /* Put data */
cnt++;
fpoint++;
fsub = fsize - fpoint;
csum = ch + csum;
if (fsub == 0 || cnt == 0x20) {
cnt = 0;
csum = 0xFF & (~csum + 1);
fprintf(outp, "%02X\n", csum); /* Put checksum */
if (fsub == 0)
break;
if (adrs > 0xFFFF) {
ofsa = 0x1000 + ofsa;
adrs = 0;
fprintf(outp, ":02000002%04X", ofsa); /* Change offset address */
csum = 0x02 + 0x02 + (ofsa >> 8) + (ofsa & 0xFF);
csum = 0xFF & (~csum + 1);
fprintf(outp, "%02X\n", csum);
}
adrs = 0xFFFF & adrs;
if (fsub > 0x20) {
fprintf(outp, ":20%04X00",
(unsigned) adrs); /* Next Hex line Header */
csum = 0x20 + (adrs >> 8) + (adrs & 0xFF);
adrs += 0x20;
} else {
if (fsub > 0) {
fprintf(outp, ":%02X%04X00", (unsigned) fsub,
(unsigned) adrs); /* Next Hex line Header */
csum = fsub + (adrs >> 8) + (adrs & 0xFF);
adrs += fsub;
}
}
}
}
if (eofrec == 0)
fprintf(outp, ":00000001FF\n"); /* End footer */
fflush(outp);

fstat(fileno(outp), &statbuf);
if (quiet == 0) printf("Output file size=%ld\n",(long)statbuf.st_size);
fstat(fileno(outp), &statbuf);
if (quiet == 0)
printf("Output file size=%ld\n", (long) statbuf.st_size);

fclose(inp);
fclose(outp);
return EXIT_SUCCESS;
fclose(inp);
fclose(outp);
return EXIT_SUCCESS;
}
1 change: 1 addition & 0 deletions cpmsim/srctools/mkdskimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int main(int argc, char *argv[])
}
memset((char *) sector, 0xe5, 128);
if ((fd = open(fn, O_RDONLY)) != -1) {
close(fd);
printf("disk file \"%s\" exists, aborting\n", fn);
exit(EXIT_FAILURE);
}
Expand Down
Loading

0 comments on commit 635f663

Please sign in to comment.