~ chicken-core (chicken-5) ee62f799c536b80924897a5b064bc001102ae242
commit ee62f799c536b80924897a5b064bc001102ae242 Author: Peter Bex <peter@more-magic.net> AuthorDate: Mon Feb 15 20:49:43 2016 +0100 Commit: Evan Hanson <evhan@foldling.org> CommitDate: Wed Feb 17 12:41:05 2016 +1300 Replace strndup() with strdup() for compat reasons This is the only thing preventing successful build for MingW on Vista. Also fix the default port, if only a plain hostname was supplied in the CHICKEN_DEBUGGER environment variable. Before, it would have been reading an uninitialized variable and always copying the full string as a host name due to an unintended cast to unsigned because of a bad stop condition in the loop. Signed-off-by: Evan Hanson <evhan@foldling.org> diff --git a/dbg-stub.c b/dbg-stub.c index c340e457..58c4205c 100644 --- a/dbg-stub.c +++ b/dbg-stub.c @@ -485,7 +485,7 @@ connect_to_debugger() static char info[ 256 ]; struct hostent *he; struct sockaddr_in sa; - int i, port; + int i, port = DEFAULT_DEBUGGER_PORT; int yes = 1; int r; @@ -494,14 +494,15 @@ connect_to_debugger() if(addr == NULL) return C_SCHEME_FALSE; /* no debugger address given */ /* parse host and port number */ - for(i = C_strlen(addr) - 1; i >= 0; --i) { + for(i = C_strlen(addr) - 1; i > 0; --i) { if(addr[ i ] == ':') break; } if(i == 0) host = addr; else { port = atoi(addr + i + 1); - host = strndup(addr, i); + host = C_strdup(addr); + addr[i] = '\0'; /* We don't use strndup() for compat reasons */ } #ifdef _WIN32Trap