SCP: Various cleanups.

- Avoid assignments of void * values.  Cast all memory allocation return values to appropriate types.
- Add output to sim_log where missing in various places.
- Fixed issue with lost file positions after a restore for devices which leverage the UNIT_SEQ flag.
This commit is contained in:
Mark Pizzolato 2013-11-20 09:13:27 -08:00
parent 3519c6c74b
commit 2e85e74699
11 changed files with 110 additions and 61 deletions

31
scp.c
View file

@ -798,7 +798,7 @@ static CTAB cmd_table[] = {
static static
int setenv(const char *envname, const char *envval, int overwrite) int setenv(const char *envname, const char *envval, int overwrite)
{ {
char *envstr = malloc(strlen(envname)+strlen(envval)+2); char *envstr = (char *)malloc(strlen(envname)+strlen(envval)+2);
int r; int r;
sprintf(envstr, "%s=%s", envname, envval); sprintf(envstr, "%s=%s", envname, envval);
@ -993,7 +993,7 @@ if (gbuf[0] == '\0') { /* Token started with qu
if (cptr) if (cptr)
*cptr = '\0'; *cptr = '\0';
} }
sim_prompt = realloc (sim_prompt, strlen (gbuf) + 2); /* nul terminator and trailing blank */ sim_prompt = (char *)realloc (sim_prompt, strlen (gbuf) + 2); /* nul terminator and trailing blank */
sprintf (sim_prompt, "%s ", gbuf); sprintf (sim_prompt, "%s ", gbuf);
return SCPE_OK; return SCPE_OK;
} }
@ -1073,7 +1073,7 @@ if (!found) {
fprintf (st, "No register help is available for the %s device\n", dptr->name); fprintf (st, "No register help is available for the %s device\n", dptr->name);
} }
else { else {
namebuf = calloc (max_namelen + 1, sizeof (*namebuf)); namebuf = (char *)calloc (max_namelen + 1, sizeof (*namebuf));
fprintf (st, "\nThe %s device implements these registers:\n\n", dptr->name); fprintf (st, "\nThe %s device implements these registers:\n\n", dptr->name);
for (rptr = dptr->registers; rptr->name != NULL; rptr++) { for (rptr = dptr->registers; rptr->name != NULL; rptr++) {
if (rptr->flags & REG_HIDDEN) if (rptr->flags & REG_HIDDEN)
@ -1577,7 +1577,7 @@ if (flag >= 0) { /* Only bump nesting fro
sim_on_check[sim_do_depth] = sim_on_check[sim_do_depth-1]; /* inherit On mode */ sim_on_check[sim_do_depth] = sim_on_check[sim_do_depth-1]; /* inherit On mode */
for (i=0; i<SCPE_MAX_ERR; i++) { /* replicate any on commands */ for (i=0; i<SCPE_MAX_ERR; i++) { /* replicate any on commands */
if (sim_on_actions[sim_do_depth-1][i]) { if (sim_on_actions[sim_do_depth-1][i]) {
sim_on_actions[sim_do_depth][i] = malloc(1+strlen(sim_on_actions[sim_do_depth-1][i])); sim_on_actions[sim_do_depth][i] = (char *)malloc(1+strlen(sim_on_actions[sim_do_depth-1][i]));
if (NULL == sim_on_actions[sim_do_depth][i]) { if (NULL == sim_on_actions[sim_do_depth][i]) {
while (--i >= 0) { while (--i >= 0) {
free(sim_on_actions[sim_do_depth][i]); free(sim_on_actions[sim_do_depth][i]);
@ -1782,7 +1782,7 @@ char *ip = instr, *op, *ap, *oend, *istart, *tmpbuf;
char rbuf[CBUFSIZE]; char rbuf[CBUFSIZE];
int i; int i;
tmpbuf = malloc(instr_size); tmpbuf = (char *)malloc(instr_size);
op = tmpbuf; op = tmpbuf;
oend = tmpbuf + instr_size - 2; oend = tmpbuf + instr_size - 2;
while (isspace (*ip)) /* skip leading spaces */ while (isspace (*ip)) /* skip leading spaces */
@ -2072,7 +2072,7 @@ if ((NULL == cptr) || ('\0' == *cptr)) { /* Empty Action */
sim_on_actions[sim_do_depth][cond] = NULL; } sim_on_actions[sim_do_depth][cond] = NULL; }
else { else {
sim_on_actions[sim_do_depth][cond] = sim_on_actions[sim_do_depth][cond] =
realloc(sim_on_actions[sim_do_depth][cond], 1+strlen(cptr)); (char *)realloc(sim_on_actions[sim_do_depth][cond], 1+strlen(cptr));
strcpy(sim_on_actions[sim_do_depth][cond], cptr); strcpy(sim_on_actions[sim_do_depth][cond], cptr);
} }
return SCPE_OK; return SCPE_OK;
@ -2112,13 +2112,13 @@ sim_on_check[sim_do_depth] = flag;
if ((sim_do_depth != 0) && if ((sim_do_depth != 0) &&
(NULL == sim_on_actions[sim_do_depth][0])) { /* default handler set? */ (NULL == sim_on_actions[sim_do_depth][0])) { /* default handler set? */
sim_on_actions[sim_do_depth][0] = /* No, so make "RETURN" */ sim_on_actions[sim_do_depth][0] = /* No, so make "RETURN" */
malloc(1+strlen("RETURN")); /* be the default action */ (char *)malloc(1+strlen("RETURN")); /* be the default action */
strcpy(sim_on_actions[sim_do_depth][0], "RETURN"); strcpy(sim_on_actions[sim_do_depth][0], "RETURN");
} }
if ((sim_do_depth != 0) && if ((sim_do_depth != 0) &&
(NULL == sim_on_actions[sim_do_depth][SCPE_AFAIL])) {/* handler set for AFAIL? */ (NULL == sim_on_actions[sim_do_depth][SCPE_AFAIL])) {/* handler set for AFAIL? */
sim_on_actions[sim_do_depth][SCPE_AFAIL] = /* No, so make "RETURN" */ sim_on_actions[sim_do_depth][SCPE_AFAIL] = /* No, so make "RETURN" */
malloc(1+strlen("RETURN")); /* be the action */ (char *)malloc(1+strlen("RETURN")); /* be the action */
strcpy(sim_on_actions[sim_do_depth][SCPE_AFAIL], "RETURN"); strcpy(sim_on_actions[sim_do_depth][SCPE_AFAIL], "RETURN");
} }
return SCPE_OK; return SCPE_OK;
@ -4288,12 +4288,12 @@ for ( ;; ) { /* device loop */
if (flg & UNIT_RO) /* [V2.10+] saved flgs & RO? */ if (flg & UNIT_RO) /* [V2.10+] saved flgs & RO? */
sim_switches |= SWMASK ('R'); /* RO attach */ sim_switches |= SWMASK ('R'); /* RO attach */
/* add unit to list of units to attach after registers are read */ /* add unit to list of units to attach after registers are read */
attunits = realloc (attunits, sizeof (*attunits)*(attcnt+1)); attunits = (UNIT **)realloc (attunits, sizeof (*attunits)*(attcnt+1));
attunits[attcnt] = uptr; attunits[attcnt] = uptr;
attnames = realloc (attnames, sizeof (*attnames)*(attcnt+1)); attnames = (char **)realloc (attnames, sizeof (*attnames)*(attcnt+1));
attnames[attcnt] = malloc(1+strlen(buf)); attnames[attcnt] = (char *)malloc(1+strlen(buf));
strcpy (attnames[attcnt], buf); strcpy (attnames[attcnt], buf);
attswitches = realloc (attswitches, sizeof (*attswitches)*(attcnt+1)); attswitches = (int32 *)realloc (attswitches, sizeof (*attswitches)*(attcnt+1));
attswitches[attcnt] = sim_switches; attswitches[attcnt] = sim_switches;
++attcnt; ++attcnt;
} }
@ -4397,6 +4397,7 @@ for ( ;; ) { /* device loop */
for (j=0, r = SCPE_OK; j<attcnt; j++) { for (j=0, r = SCPE_OK; j<attcnt; j++) {
if (r == SCPE_OK) { if (r == SCPE_OK) {
struct stat fstat; struct stat fstat;
t_addr saved_pos;
dptr = find_dev_from_unit (attunits[j]); dptr = find_dev_from_unit (attunits[j]);
if ((!force_restore) && if ((!force_restore) &&
@ -4411,8 +4412,10 @@ for (j=0, r = SCPE_OK; j<attcnt; j++) {
} }
continue; continue;
} }
saved_pos = attunits[j]->pos;
sim_switches = attswitches[j]; sim_switches = attswitches[j];
r = scp_attach_unit (dptr, attunits[j], attnames[j]);/* reattach unit */ r = scp_attach_unit (dptr, attunits[j], attnames[j]);/* reattach unit */
attunits[j]->pos = saved_pos;
if (r != SCPE_OK) { if (r != SCPE_OK) {
printf ("Error Attaching %s to %s\n", sim_dname (dptr), attnames[j]); printf ("Error Attaching %s to %s\n", sim_dname (dptr), attnames[j]);
if (sim_log) if (sim_log)
@ -5705,7 +5708,7 @@ for (i = 0; i < sim_internal_device_count; i++)
if (sim_internal_devices[i] == dptr) if (sim_internal_devices[i] == dptr)
return SCPE_OK; return SCPE_OK;
++sim_internal_device_count; ++sim_internal_device_count;
sim_internal_devices = realloc(sim_internal_devices, (sim_internal_device_count+1)*sizeof(*sim_internal_devices)); sim_internal_devices = (DEVICE **)realloc(sim_internal_devices, (sim_internal_device_count+1)*sizeof(*sim_internal_devices));
sim_internal_devices[sim_internal_device_count-1] = dptr; sim_internal_devices[sim_internal_device_count-1] = dptr;
sim_internal_devices[sim_internal_device_count] = NULL; sim_internal_devices[sim_internal_device_count] = NULL;
return SCPE_OK; return SCPE_OK;
@ -7099,7 +7102,7 @@ if (sim_deb && (dptr->dctrl & dbits)) {
/* Set unterminated flag for next time */ /* Set unterminated flag for next time */
debug_unterm = (len && (buf[len-1]=='\n')) ? 0 : 1; debug_unterm = len ? (((buf[len-1]=='\n')) ? 0 : 1) : debug_unterm;
if (buf != stackbuf) if (buf != stackbuf)
free (buf); free (buf);
} }

1
scp.h
View file

@ -136,6 +136,7 @@ BRKTAB *sim_brk_fnd (t_addr loc);
uint32 sim_brk_test (t_addr bloc, uint32 btyp); uint32 sim_brk_test (t_addr bloc, uint32 btyp);
void sim_brk_clrspc (uint32 spc); void sim_brk_clrspc (uint32 spc);
char *match_ext (char *fnam, char *ext); char *match_ext (char *fnam, char *ext);
t_stat show_version (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat set_dev_debug (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr); t_stat set_dev_debug (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_dev_debug (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr); t_stat show_dev_debug (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
const char *sim_error_text (t_stat stat); const char *sim_error_text (t_stat stat);

View file

@ -104,7 +104,7 @@ while (fgets (line, sizeof(line)-1, iFile)) {
case '\n': case '\n':
break; break;
case 'u': /* unsigned char {array_name}[] */ case 'u': /* unsigned char {array_name}[] */
*prom_array_name = calloc(512, sizeof(char)); *prom_array_name = (char *)calloc(512, sizeof(char));
if (1 == sscanf (line, "unsigned char %s[]", *prom_array_name)) { if (1 == sscanf (line, "unsigned char %s[]", *prom_array_name)) {
c = strchr (*prom_array_name, '['); c = strchr (*prom_array_name, '[');
if (c) if (c)
@ -116,7 +116,7 @@ while (fgets (line, sizeof(line)-1, iFile)) {
while (1 == sscanf (c, "0x%2Xd,", &byte)) { while (1 == sscanf (c, "0x%2Xd,", &byte)) {
if (bytes_written >= allocated_size) { if (bytes_written >= allocated_size) {
allocated_size += 2048; allocated_size += 2048;
*pROMData = realloc(*pROMData, allocated_size); *pROMData = (unsigned char *)realloc(*pROMData, allocated_size);
} }
*(*pROMData + bytes_written++) = byte; *(*pROMData + bytes_written++) = byte;
c += 5; c += 5;
@ -155,7 +155,7 @@ if (stat (rom_filename, &statb)) {
fclose (rFile); fclose (rFile);
return -1; return -1;
} }
ROMData = malloc (statb.st_size); ROMData = (unsigned char *)malloc (statb.st_size);
if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) { if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) {
printf ("Error reading '%s': %s\n", rom_filename, strerror(errno)); printf ("Error reading '%s': %s\n", rom_filename, strerror(errno));
fclose (rFile); fclose (rFile);
@ -242,7 +242,7 @@ if (statb.st_size != expected_size) {
fclose (rFile); fclose (rFile);
return -1; return -1;
} }
ROMData = malloc (statb.st_size); ROMData = (unsigned char *)malloc (statb.st_size);
if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) { if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) {
printf ("Error reading '%s': %s\n", rom_filename, strerror(errno)); printf ("Error reading '%s': %s\n", rom_filename, strerror(errno));
fclose (rFile); fclose (rFile);

View file

@ -618,7 +618,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0);
} }
if (sim_rem_buf_ptr[i]+80 >= sim_rem_buf_size[i]) { if (sim_rem_buf_ptr[i]+80 >= sim_rem_buf_size[i]) {
sim_rem_buf_size[i] += 1024; sim_rem_buf_size[i] += 1024;
sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]);
} }
strcpy (sim_rem_buf[i], "CONTINUE ! Automatic continue due to timeout"); strcpy (sim_rem_buf[i], "CONTINUE ! Automatic continue due to timeout");
tmxr_linemsgf (lp, "%s\n", sim_rem_buf[i]); tmxr_linemsgf (lp, "%s\n", sim_rem_buf[i]);
@ -656,7 +656,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0);
tmxr_linemsg (lp, "\r\n"); tmxr_linemsg (lp, "\r\n");
if (sim_rem_buf_ptr[i]+1 >= sim_rem_buf_size[i]) { if (sim_rem_buf_ptr[i]+1 >= sim_rem_buf_size[i]) {
sim_rem_buf_size[i] += 1024; sim_rem_buf_size[i] += 1024;
sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]);
} }
sim_rem_buf[i][sim_rem_buf_ptr[i]++] = '\0'; sim_rem_buf[i][sim_rem_buf_ptr[i]++] = '\0';
got_command = TRUE; got_command = TRUE;
@ -670,7 +670,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0);
if (!sim_rem_single_mode[i]) { if (!sim_rem_single_mode[i]) {
if (sim_rem_buf_ptr[i]+80 >= sim_rem_buf_size[i]) { if (sim_rem_buf_ptr[i]+80 >= sim_rem_buf_size[i]) {
sim_rem_buf_size[i] += 1024; sim_rem_buf_size[i] += 1024;
sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]);
} }
strcpy (sim_rem_buf[i], "CONTINUE ! Automatic continue before close"); strcpy (sim_rem_buf[i], "CONTINUE ! Automatic continue before close");
tmxr_linemsgf (lp, "%s\n", sim_rem_buf[i]); tmxr_linemsgf (lp, "%s\n", sim_rem_buf[i]);
@ -682,7 +682,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0);
tmxr_putc_ln (lp, c); tmxr_putc_ln (lp, c);
if (sim_rem_buf_ptr[i]+2 >= sim_rem_buf_size[i]) { if (sim_rem_buf_ptr[i]+2 >= sim_rem_buf_size[i]) {
sim_rem_buf_size[i] += 1024; sim_rem_buf_size[i] += 1024;
sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]);
} }
sim_rem_buf[i][sim_rem_buf_ptr[i]++] = c; sim_rem_buf[i][sim_rem_buf_ptr[i]++] = c;
sim_rem_buf[i][sim_rem_buf_ptr[i]] = '\0'; sim_rem_buf[i][sim_rem_buf_ptr[i]] = '\0';
@ -895,15 +895,15 @@ if (sim_rem_con_tmxr.master)
for (i=0; i<sim_rem_con_tmxr.lines; i++) for (i=0; i<sim_rem_con_tmxr.lines; i++)
free (sim_rem_buf[i]); free (sim_rem_buf[i]);
sim_rem_con_tmxr.lines = lines; sim_rem_con_tmxr.lines = lines;
sim_rem_con_tmxr.ldsc = realloc (sim_rem_con_tmxr.ldsc, sizeof(*sim_rem_con_tmxr.ldsc)*lines); sim_rem_con_tmxr.ldsc = (TMLN *)realloc (sim_rem_con_tmxr.ldsc, sizeof(*sim_rem_con_tmxr.ldsc)*lines);
memset (sim_rem_con_tmxr.ldsc, 0, sizeof(*sim_rem_con_tmxr.ldsc)*lines); memset (sim_rem_con_tmxr.ldsc, 0, sizeof(*sim_rem_con_tmxr.ldsc)*lines);
sim_rem_buf = realloc (sim_rem_buf, sizeof(*sim_rem_buf)*lines); sim_rem_buf = (char **)realloc (sim_rem_buf, sizeof(*sim_rem_buf)*lines);
memset (sim_rem_buf, 0, sizeof(*sim_rem_buf)*lines); memset (sim_rem_buf, 0, sizeof(*sim_rem_buf)*lines);
sim_rem_buf_size = realloc (sim_rem_buf_size, sizeof(*sim_rem_buf_size)*lines); sim_rem_buf_size = (int32 *)realloc (sim_rem_buf_size, sizeof(*sim_rem_buf_size)*lines);
memset (sim_rem_buf_size, 0, sizeof(*sim_rem_buf_size)*lines); memset (sim_rem_buf_size, 0, sizeof(*sim_rem_buf_size)*lines);
sim_rem_buf_ptr = realloc (sim_rem_buf_ptr, sizeof(*sim_rem_buf_ptr)*lines); sim_rem_buf_ptr = (int32 *)realloc (sim_rem_buf_ptr, sizeof(*sim_rem_buf_ptr)*lines);
memset (sim_rem_buf_ptr, 0, sizeof(*sim_rem_buf_ptr)*lines); memset (sim_rem_buf_ptr, 0, sizeof(*sim_rem_buf_ptr)*lines);
sim_rem_single_mode = realloc (sim_rem_single_mode, sizeof(*sim_rem_single_mode)*lines); sim_rem_single_mode = (t_bool *)realloc (sim_rem_single_mode, sizeof(*sim_rem_single_mode)*lines);
memset (sim_rem_single_mode, 0, sizeof(*sim_rem_single_mode)*lines); memset (sim_rem_single_mode, 0, sizeof(*sim_rem_single_mode)*lines);
return SCPE_OK; return SCPE_OK;
} }
@ -1086,6 +1086,7 @@ if (sim_log) {
} }
time(&now); time(&now);
fprintf (sim_deb, "Debug output to \"%s\" at %s", sim_logfile_name (sim_deb, sim_deb_ref), ctime(&now)); fprintf (sim_deb, "Debug output to \"%s\" at %s", sim_logfile_name (sim_deb, sim_deb_ref), ctime(&now));
show_version (sim_deb, NULL, NULL, 0, NULL);
return SCPE_OK; return SCPE_OK;
} }
@ -1381,7 +1382,7 @@ else if (strcmp (gbuf, "STDERR") == 0) { /* output to stderr? */
*pref = NULL; *pref = NULL;
} }
else { else {
*pref = calloc (1, sizeof(**pref)); *pref = (FILEREF *)calloc (1, sizeof(**pref));
if (!*pref) if (!*pref)
return SCPE_MEM; return SCPE_MEM;
get_glyph_nc (filename, gbuf, 0); /* reparse */ get_glyph_nc (filename, gbuf, 0); /* reparse */

View file

@ -332,7 +332,7 @@ typedef uint32 t_addr;
/* indicate inclusion on a list */ /* indicate inclusion on a list */
/* and */ /* and */
/* 2 - to not be a valid/possible pointer (alignment) */ /* 2 - to not be a valid/possible pointer (alignment) */
#define QUEUE_LIST_END ((void *)1) #define QUEUE_LIST_END ((UNIT *)1)
/* Device data structure */ /* Device data structure */
@ -1020,8 +1020,8 @@ extern int32 sim_asynch_inst_latency;
#else #else
#error "Implementation of function InterlockedCompareExchangePointer() is needed to build with USE_AIO_INTRINSICS" #error "Implementation of function InterlockedCompareExchangePointer() is needed to build with USE_AIO_INTRINSICS"
#endif #endif
#define AIO_QUEUE_VAL InterlockedCompareExchangePointer(&sim_asynch_queue, sim_asynch_queue, NULL) #define AIO_QUEUE_VAL (UNIT *)(InterlockedCompareExchangePointer(&sim_asynch_queue, sim_asynch_queue, NULL))
#define AIO_QUEUE_SET(val, queue) InterlockedCompareExchangePointer(&sim_asynch_queue, val, queue) #define AIO_QUEUE_SET(val, queue) (UNIT *)(InterlockedCompareExchangePointer(&sim_asynch_queue, val, queue))
#define AIO_UPDATE_QUEUE \ #define AIO_UPDATE_QUEUE \
if (AIO_QUEUE_VAL != QUEUE_LIST_END) { /* List !Empty */ \ if (AIO_QUEUE_VAL != QUEUE_LIST_END) { /* List !Empty */ \
UNIT *q, *uptr; \ UNIT *q, *uptr; \

View file

@ -876,13 +876,19 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop
sim_switches = saved_sim_switches; sim_switches = saved_sim_switches;
return r; return r;
} }
if (!sim_quiet) if (!sim_quiet) {
printf ("%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); printf ("%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf);
if (sim_log)
fprintf (sim_log, "%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf);
}
capac_factor = ((dptr->dwidth / dptr->aincr) == 16) ? 2 : 1; /* capacity units (word: 2, byte: 1) */ capac_factor = ((dptr->dwidth / dptr->aincr) == 16) ? 2 : 1; /* capacity units (word: 2, byte: 1) */
vhd = sim_vhd_disk_create (gbuf, ((t_offset)uptr->capac)*capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1)); vhd = sim_vhd_disk_create (gbuf, ((t_offset)uptr->capac)*capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1));
if (!vhd) { if (!vhd) {
if (!sim_quiet) if (!sim_quiet) {
printf ("%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); printf ("%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf);
if (sim_log)
fprintf (sim_log, "%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf);
}
return SCPE_OPENERR; return SCPE_OPENERR;
} }
else { else {
@ -898,8 +904,11 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop
return SCPE_MEM; return SCPE_MEM;
} }
for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) { for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) {
if (!sim_quiet) if (!sim_quiet) {
printf ("%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); printf ("%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors));
if (sim_log)
fprintf (sim_log, "%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors));
}
sects = sectors_per_buffer; sects = sectors_per_buffer;
if (lba + sects > total_sectors) if (lba + sects > total_sectors)
sects = total_sectors - lba; sects = total_sectors - lba;
@ -916,10 +925,16 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop
} }
} }
if (!sim_quiet) { if (!sim_quiet) {
if (r == SCPE_OK) if (r == SCPE_OK) {
printf ("\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); printf ("\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000));
else if (sim_log)
fprintf (sim_log, "\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000));
}
else {
printf ("\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r)); printf ("\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r));
if (sim_log)
fprintf (sim_log, "\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r));
}
} }
if ((r == SCPE_OK) && (sim_switches & SWMASK ('V'))) { if ((r == SCPE_OK) && (sim_switches & SWMASK ('V'))) {
uint8 *verify_buf = (uint8*) malloc (1024*1024); uint8 *verify_buf = (uint8*) malloc (1024*1024);
@ -931,8 +946,11 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop
return SCPE_MEM; return SCPE_MEM;
} }
for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) { for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) {
if (!sim_quiet) if (!sim_quiet) {
printf ("%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); printf ("%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors));
if (sim_log)
fprintf (sim_log, "%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors));
}
sects = sectors_per_buffer; sects = sectors_per_buffer;
if (lba + sects > total_sectors) if (lba + sects > total_sectors)
sects = total_sectors - lba; sects = total_sectors - lba;
@ -953,8 +971,11 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop
} }
} }
if (!sim_quiet) { if (!sim_quiet) {
if (r == SCPE_OK) if (r == SCPE_OK) {
printf ("\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); printf ("\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000));
if (sim_log)
fprintf (sim_log, "\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000));
}
else { else {
t_lba i; t_lba i;
uint32 save_dctrl = dptr->dctrl; uint32 save_dctrl = dptr->dctrl;
@ -964,6 +985,8 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop
if (0 != memcmp (copy_buf+i*sector_size, verify_buf+i*sector_size, sector_size)) if (0 != memcmp (copy_buf+i*sector_size, verify_buf+i*sector_size, sector_size))
break; break;
printf ("\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i); printf ("\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i);
if (sim_log)
fprintf (sim_log, "\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i);
dptr->dctrl = 0xFFFFFFFF; dptr->dctrl = 0xFFFFFFFF;
sim_deb = stdout; sim_deb = stdout;
sim_disk_data_trace (uptr, copy_buf+i*sector_size, lba+i, sector_size, "Expected", TRUE, 1); sim_disk_data_trace (uptr, copy_buf+i*sector_size, lba+i, sector_size, "Expected", TRUE, 1);
@ -1052,8 +1075,11 @@ if (sim_switches & SWMASK ('R')) { /* read only? */
if (uptr->fileref == NULL) /* open fail? */ if (uptr->fileref == NULL) /* open fail? */
return _err_return (uptr, SCPE_OPENERR); /* yes, error */ return _err_return (uptr, SCPE_OPENERR); /* yes, error */
uptr->flags = uptr->flags | UNIT_RO; /* set rd only */ uptr->flags = uptr->flags | UNIT_RO; /* set rd only */
if (!sim_quiet) if (!sim_quiet) {
printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units));
if (sim_log)
fprintf (sim_log, "%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units));
}
} }
else { /* normal */ else { /* normal */
uptr->fileref = open_function (cptr, "rb+"); /* open r/w */ uptr->fileref = open_function (cptr, "rb+"); /* open r/w */
@ -1102,7 +1128,7 @@ if (storage_function)
if ((created) && (!copied)) { if ((created) && (!copied)) {
t_stat r = SCPE_OK; t_stat r = SCPE_OK;
uint8 *secbuf = calloc (1, ctx->sector_size); /* alloc temp sector buf */ uint8 *secbuf = (uint8 *)calloc (1, ctx->sector_size); /* alloc temp sector buf */
/* /*
On a newly created disk, we write a zero sector to the last and the On a newly created disk, we write a zero sector to the last and the
@ -1141,6 +1167,13 @@ if (capac && (capac != (t_offset)-1)) {
printf ("%s < ", (ctx->capac_factor == 2) ? "W" : ""); printf ("%s < ", (ctx->capac_factor == 2) ? "W" : "");
fprint_val (stdout, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT); fprint_val (stdout, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT);
printf ("%s)\n", (ctx->capac_factor == 2) ? "W" : ""); printf ("%s)\n", (ctx->capac_factor == 2) ? "W" : "");
if (sim_log) {
fprintf (sim_log, "%s%d: non expandable disk %s is smaller than simulated device (", sim_dname (dptr), (int)(uptr-dptr->units), cptr);
fprint_val (sim_log, (t_addr)(capac/ctx->capac_factor), 10, T_ADDR_W, PV_LEFT);
fprintf (sim_log, "%s < ", (ctx->capac_factor == 2) ? "W" : "");
fprint_val (sim_log, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT);
fprintf (sim_log, "%s)\n", (ctx->capac_factor == 2) ? "W" : "");
}
} }
} }
} }

View file

@ -670,7 +670,7 @@ static int eth_open_device_count = 0;
#if defined (USE_NETWORK) || defined (USE_SHARED) #if defined (USE_NETWORK) || defined (USE_SHARED)
static void _eth_add_to_open_list (ETH_DEV* dev) static void _eth_add_to_open_list (ETH_DEV* dev)
{ {
eth_open_devices = realloc(eth_open_devices, (eth_open_device_count+1)*sizeof(*eth_open_devices)); eth_open_devices = (ETH_DEV**)realloc(eth_open_devices, (eth_open_device_count+1)*sizeof(*eth_open_devices));
eth_open_devices[eth_open_device_count++] = dev; eth_open_devices[eth_open_device_count++] = dev;
} }
@ -824,7 +824,7 @@ void ethq_insert_data(ETH_QUE* que, int32 type, const uint8 *data, int used, siz
memcpy(&item->packet.msg[len], crc_data, ETH_CRC_SIZE); memcpy(&item->packet.msg[len], crc_data, ETH_CRC_SIZE);
} }
else { else {
item->packet.oversize = realloc (item->packet.oversize, ((len > crc_len) ? len : crc_len)); item->packet.oversize = (uint8 *)realloc (item->packet.oversize, ((len > crc_len) ? len : crc_len));
memcpy(item->packet.oversize, data, ((len > crc_len) ? len : crc_len)); memcpy(item->packet.oversize, data, ((len > crc_len) ? len : crc_len));
if (crc_data && (crc_len > len)) if (crc_data && (crc_len > len))
memcpy(&item->packet.oversize[len], crc_data, ETH_CRC_SIZE); memcpy(&item->packet.oversize[len], crc_data, ETH_CRC_SIZE);
@ -1282,7 +1282,7 @@ static int pcap_mac_if_win32(char *AdapterName, unsigned char MACAddress[6])
/* Allocate a buffer to get the MAC adress */ /* Allocate a buffer to get the MAC adress */
OidData = malloc(6 + sizeof(PACKET_OID_DATA)); OidData = (PACKET_OID_DATA *)malloc(6 + sizeof(PACKET_OID_DATA));
if (OidData == NULL) { if (OidData == NULL) {
p_PacketCloseAdapter(lpAdapter); p_PacketCloseAdapter(lpAdapter);
#ifdef _WIN32 #ifdef _WIN32
@ -1845,7 +1845,7 @@ if (sim_log) fprintf (sim_log, msg, savname);
eth_get_nic_hw_addr(dev, savname); eth_get_nic_hw_addr(dev, savname);
/* save name of device */ /* save name of device */
dev->name = malloc(strlen(savname)+1); dev->name = (char *)malloc(strlen(savname)+1);
strcpy(dev->name, savname); strcpy(dev->name, savname);
/* save debugging information */ /* save debugging information */
@ -2216,7 +2216,7 @@ if (NULL != (request = dev->write_buffers))
dev->write_buffers = request->next; dev->write_buffers = request->next;
pthread_mutex_unlock (&dev->writer_lock); pthread_mutex_unlock (&dev->writer_lock);
if (NULL == request) if (NULL == request)
request = malloc(sizeof(*request)); request = (struct write_request *)malloc(sizeof(*request));
/* Copy buffer contents */ /* Copy buffer contents */
request->packet.len = packet->len; request->packet.len = packet->len;
@ -2700,7 +2700,7 @@ int bpf_used;
if ((dev->have_host_nic_phy_addr) && if ((dev->have_host_nic_phy_addr) &&
(LOOPBACK_PHYSICAL_RESPONSE(dev->host_nic_phy_hw_addr, dev->physical_addr, data))) { (LOOPBACK_PHYSICAL_RESPONSE(dev->host_nic_phy_hw_addr, dev->physical_addr, data))) {
u_char *datacopy = malloc(header->len); u_char *datacopy = (u_char *)malloc(header->len);
memcpy(datacopy, data, header->len); memcpy(datacopy, data, header->len);
memcpy(datacopy, dev->physical_addr, sizeof(ETH_MAC)); memcpy(datacopy, dev->physical_addr, sizeof(ETH_MAC));
@ -2781,10 +2781,10 @@ if (bpf_used ? to_me : (to_me && !from_me)) {
int crc_len = 0; int crc_len = 0;
uint8 crc_data[4]; uint8 crc_data[4];
uint32 len = header->len; uint32 len = header->len;
u_char* moved_data = NULL; u_char *moved_data = NULL;
if (header->len < ETH_MIN_PACKET) { /* Pad runt packets before CRC append */ if (header->len < ETH_MIN_PACKET) { /* Pad runt packets before CRC append */
moved_data = malloc(ETH_MIN_PACKET); moved_data = (u_char *)malloc(ETH_MIN_PACKET);
memcpy(moved_data, data, len); memcpy(moved_data, data, len);
memset(moved_data + len, 0, ETH_MIN_PACKET-len); memset(moved_data + len, 0, ETH_MIN_PACKET-len);
len = ETH_MIN_PACKET; len = ETH_MIN_PACKET;

View file

@ -182,7 +182,7 @@ return NULL;
static struct open_serial_device *_serial_add_to_open_list (SERHANDLE port, TMLN *line, const char *name, const char *config) static struct open_serial_device *_serial_add_to_open_list (SERHANDLE port, TMLN *line, const char *name, const char *config)
{ {
serial_open_devices = realloc(serial_open_devices, (++serial_open_device_count)*sizeof(*serial_open_devices)); serial_open_devices = (struct open_serial_device *)realloc(serial_open_devices, (++serial_open_device_count)*sizeof(*serial_open_devices));
memset(&serial_open_devices[serial_open_device_count-1], 0, sizeof(serial_open_devices[serial_open_device_count-1])); memset(&serial_open_devices[serial_open_device_count-1], 0, sizeof(serial_open_devices[serial_open_device_count-1]));
serial_open_devices[serial_open_device_count-1].port = port; serial_open_devices[serial_open_device_count-1].port = port;
serial_open_devices[serial_open_device_count-1].line = line; serial_open_devices[serial_open_device_count-1].line = line;
@ -455,7 +455,7 @@ if (status != SCPE_OK) { /* port configuration er
} }
if ((port != INVALID_HANDLE) && (*config) && (lp)) { if ((port != INVALID_HANDLE) && (*config) && (lp)) {
lp->serconfig = realloc (lp->serconfig, 1 + strlen (config)); lp->serconfig = (char *)realloc (lp->serconfig, 1 + strlen (config));
strcpy (lp->serconfig, config); strcpy (lp->serconfig, config);
} }
if (port != INVALID_HANDLE) if (port != INVALID_HANDLE)
@ -506,7 +506,7 @@ if (strcmp (sptr, ".5") == 0) /* 1.5 stop bits request
r = sim_config_os_serial (port, config); r = sim_config_os_serial (port, config);
dev = _get_open_device (port); dev = _get_open_device (port);
if (dev) { if (dev) {
dev->line->serconfig = realloc (dev->line->serconfig, 1 + strlen (sconfig)); dev->line->serconfig = (char *)realloc (dev->line->serconfig, 1 + strlen (sconfig));
strcpy (dev->line->serconfig, sconfig); strcpy (dev->line->serconfig, sconfig);
} }
return r; return r;

View file

@ -134,6 +134,7 @@ static struct sock_errors {
{WSAEISCONN, "Transport endpoint is already connected"}, {WSAEISCONN, "Transport endpoint is already connected"},
{WSAECONNRESET, "Connection reset by peer"}, {WSAECONNRESET, "Connection reset by peer"},
{WSAECONNREFUSED, "Connection refused"}, {WSAECONNREFUSED, "Connection refused"},
{WSAECONNABORTED, "Connection aborted"},
{WSAEHOSTUNREACH, "No route to host"}, {WSAEHOSTUNREACH, "No route to host"},
{WSAEADDRINUSE, "Address already in use"}, {WSAEADDRINUSE, "Address already in use"},
#if defined (WSAEAFNOSUPPORT) #if defined (WSAEAFNOSUPPORT)
@ -154,14 +155,22 @@ int32 i;
for (i=0; (sock_errors[i].text) && (sock_errors[i].value != err); i++) for (i=0; (sock_errors[i].text) && (sock_errors[i].value != err); i++)
; ;
if (sock_errors[i].value == err) if (sock_errors[i].value == err) {
printf ("Sockets: %s error %d - %s\n", emsg, err, sock_errors[i].text); printf ("Sockets: %s error %d - %s\n", emsg, err, sock_errors[i].text);
else if (sim_log)
fprintf (sim_log, "Sockets: %s error %d - %s\n", emsg, err, sock_errors[i].text);
}
else {
#if defined(_WIN32) #if defined(_WIN32)
printf ("Sockets: %s error %d\n", emsg, err); printf ("Sockets: %s error %d\n", emsg, err);
if (sim_log)
fprintf (sim_log, "Sockets: %s error %d\n", emsg, err);
#else #else
printf ("Sockets: %s error %d - %s\n", emsg, err, strerror(err)); printf ("Sockets: %s error %d - %s\n", emsg, err, strerror(err));
if (sim_log)
fprintf (sim_log, "Sockets: %s error %d - %s\n", emsg, err, strerror(err));
#endif #endif
}
if (s != INVALID_SOCKET) if (s != INVALID_SOCKET)
sim_close_sock (s, flg); sim_close_sock (s, flg);
return INVALID_SOCKET; return INVALID_SOCKET;
@ -319,7 +328,7 @@ else {
ips = fixed; ips = fixed;
} }
for (ip=ips; *ip != NULL; ++ip) { for (ip=ips; *ip != NULL; ++ip) {
ai = calloc(1, sizeof(*ai)); ai = (struct addrinfo *)calloc(1, sizeof(*ai));
if (NULL == ai) { if (NULL == ai) {
s_freeaddrinfo(result); s_freeaddrinfo(result);
return EAI_MEMORY; return EAI_MEMORY;
@ -331,7 +340,7 @@ for (ip=ips; *ip != NULL; ++ip) {
ai->ai_addrlen = sizeof(struct sockaddr_in); ai->ai_addrlen = sizeof(struct sockaddr_in);
ai->ai_canonname = NULL; ai->ai_canonname = NULL;
ai->ai_next = NULL; ai->ai_next = NULL;
ai->ai_addr = calloc(1, sizeof(struct sockaddr_in)); ai->ai_addr = (struct sockaddr *)calloc(1, sizeof(struct sockaddr_in));
if (NULL == ai->ai_addr) { if (NULL == ai->ai_addr) {
free(ai); free(ai);
s_freeaddrinfo(result); s_freeaddrinfo(result);
@ -348,7 +357,7 @@ for (ip=ips; *ip != NULL; ++ip) {
lai = ai; lai = ai;
} }
if (cname) { if (cname) {
result->ai_canonname = calloc(1, strlen(cname)+1); result->ai_canonname = (char *)calloc(1, strlen(cname)+1);
if (NULL == result->ai_canonname) { if (NULL == result->ai_canonname) {
s_freeaddrinfo(result); s_freeaddrinfo(result);
return EAI_MEMORY; return EAI_MEMORY;
@ -446,7 +455,8 @@ static void load_function(char* function, _func* func_ptr) {
char* msg = "Sockets: Failed to find function '%s' in %s\r\n"; char* msg = "Sockets: Failed to find function '%s' in %s\r\n";
printf (msg, function, lib_name); printf (msg, function, lib_name);
if (sim_log) fprintf (sim_log, msg, function, lib_name); if (sim_log)
fprintf (sim_log, msg, function, lib_name);
lib_loaded = 3; lib_loaded = 3;
} }
} }
@ -881,7 +891,7 @@ if (newsock == INVALID_SOCKET) { /* error? */
return INVALID_SOCKET; return INVALID_SOCKET;
} }
if (connectaddr != NULL) { if (connectaddr != NULL) {
*connectaddr = calloc(1, NI_MAXHOST+1); *connectaddr = (char *)calloc(1, NI_MAXHOST+1);
#ifdef AF_INET6 #ifdef AF_INET6
p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (0 == memcmp("::ffff:", *connectaddr, 7)) /* is this a IPv4-mapped IPv6 address? */ if (0 == memcmp("::ffff:", *connectaddr, 7)) /* is this a IPv4-mapped IPv6 address? */
@ -989,9 +999,9 @@ char hostbuf[NI_MAXHOST+1];
char portbuf[NI_MAXSERV+1]; char portbuf[NI_MAXSERV+1];
if (socknamebuf) if (socknamebuf)
*socknamebuf = calloc(1, NI_MAXHOST+NI_MAXSERV+4); *socknamebuf = (char *)calloc(1, NI_MAXHOST+NI_MAXSERV+4);
if (peernamebuf) if (peernamebuf)
*peernamebuf = calloc(1, NI_MAXHOST+NI_MAXSERV+4); *peernamebuf = (char *)calloc(1, NI_MAXHOST+NI_MAXSERV+4);
getsockname (sock, (struct sockaddr *)&sockname, &socknamesize); getsockname (sock, (struct sockaddr *)&sockname, &socknamesize);
getpeername (sock, (struct sockaddr *)&peername, &peernamesize); getpeername (sock, (struct sockaddr *)&peername, &peernamesize);
if (socknamebuf != NULL) { if (socknamebuf != NULL) {
@ -1024,6 +1034,7 @@ if (rbytes == SOCKET_ERROR) {
if ((err != WSAETIMEDOUT) && /* expected errors after a connect failure */ if ((err != WSAETIMEDOUT) && /* expected errors after a connect failure */
(err != WSAEHOSTUNREACH) && (err != WSAEHOSTUNREACH) &&
(err != WSAECONNREFUSED) && (err != WSAECONNREFUSED) &&
(err != WSAECONNABORTED) &&
(err != WSAECONNRESET)) (err != WSAECONNRESET))
sim_err_sock (INVALID_SOCKET, "read", 0); sim_err_sock (INVALID_SOCKET, "read", 0);
return -1; return -1;

View file

@ -64,6 +64,7 @@
#define WSAEISCONN EISCONN #define WSAEISCONN EISCONN
#define WSAECONNRESET ECONNRESET #define WSAECONNRESET ECONNRESET
#define WSAECONNREFUSED ECONNREFUSED #define WSAECONNREFUSED ECONNREFUSED
#define WSAECONNABORTED ECONNABORTED
#define WSAEHOSTUNREACH EHOSTUNREACH #define WSAEHOSTUNREACH EHOSTUNREACH
#define WSAEADDRINUSE EADDRINUSE #define WSAEADDRINUSE EADDRINUSE
#if defined(EAFNOSUPPORT) #if defined(EAFNOSUPPORT)

View file

@ -124,4 +124,3 @@ extern t_bool sim_asynch_timer;
extern DEVICE sim_timer_dev; extern DEVICE sim_timer_dev;
#endif #endif