mirror of
https://github.com/simh/simh.git
synced 2026-02-03 15:13:56 +00:00
ALL: Massive 'const' cleanup
These changes facilitate more robust parameter type checking and helps to identify unexpected coding errors. Most simulators can now also be compiled with a C++ compiler without warnings. Additionally, these changes have also been configured to facilitate easier backporting of simulator and device simulation modules to run under the simh v3.9+ SCP framework.
This commit is contained in:
14
sim_sock.c
14
sim_sock.c
@@ -540,8 +540,9 @@ int load_ws2(void) {
|
||||
|
||||
int sim_parse_addr (const char *cptr, char *host, size_t host_len, const char *default_host, char *port, size_t port_len, const char *default_port, const char *validate_addr)
|
||||
{
|
||||
char gbuf[CBUFSIZE];
|
||||
char *hostp, *portp;
|
||||
char gbuf[CBUFSIZE], default_pbuf[CBUFSIZE];
|
||||
const char *hostp;
|
||||
char *portp;
|
||||
char *endc;
|
||||
unsigned long portval;
|
||||
|
||||
@@ -560,6 +561,9 @@ if ((cptr == NULL) || (*cptr == 0)) {
|
||||
strcpy (port, default_port);
|
||||
return 0;
|
||||
}
|
||||
memset (default_pbuf, 0, sizeof(default_pbuf));
|
||||
if (default_port)
|
||||
strncpy (default_pbuf, default_port, sizeof(default_pbuf)-1);
|
||||
gbuf[sizeof(gbuf)-1] = '\0';
|
||||
strncpy (gbuf, cptr, sizeof(gbuf)-1);
|
||||
hostp = gbuf; /* default addr */
|
||||
@@ -568,11 +572,11 @@ if ((portp = strrchr (gbuf, ':')) && /* x:y? split */
|
||||
(NULL == strchr (portp, ']'))) {
|
||||
*portp++ = 0;
|
||||
if (*portp == '\0')
|
||||
portp = (char *)default_port;
|
||||
portp = default_pbuf;
|
||||
}
|
||||
else { /* No colon in input */
|
||||
portp = gbuf; /* Input is the port specifier */
|
||||
hostp = (char *)default_host; /* host is defaulted if provided */
|
||||
hostp = (const char *)default_host; /* host is defaulted if provided */
|
||||
}
|
||||
if (portp != NULL) {
|
||||
portval = strtoul(portp, &endc, 10);
|
||||
@@ -598,8 +602,8 @@ if (hostp != NULL) {
|
||||
return -1; /* invalid domain literal */
|
||||
/* host may be the const default_host so move to temp buffer before modifying */
|
||||
strncpy(gbuf, hostp+1, sizeof(gbuf)-1); /* remove brackets from domain literal host */
|
||||
gbuf[strlen(gbuf)-1] = '\0';
|
||||
hostp = gbuf;
|
||||
hostp[strlen(hostp)-1] = '\0';
|
||||
}
|
||||
}
|
||||
if (host) { /* host wanted? */
|
||||
|
||||
Reference in New Issue
Block a user