summaryrefslogtreecommitdiffstats
path: root/win/tclWinSock.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-07-10 11:03:23 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-07-10 11:03:23 (GMT)
commite2a8d6ca464ae7a8fefa63c1e95c9387cfdbd339 (patch)
treeedee9c4b4d6e1b9a4b1de3b967b34b92e743b325 /win/tclWinSock.c
parent5861e21598de0fa797735436c93a90ca3b32bc24 (diff)
downloadtcl-e2a8d6ca464ae7a8fefa63c1e95c9387cfdbd339.zip
tcl-e2a8d6ca464ae7a8fefa63c1e95c9387cfdbd339.tar.gz
tcl-e2a8d6ca464ae7a8fefa63c1e95c9387cfdbd339.tar.bz2
* win/tclWinSock.c (InitializeHostName): Corrected logic that
extracted the name of the computer from the gethostname call so that it would use the name on success, not failure. Also ensured that the buffer size is exactly that recommended by Microsoft.
Diffstat (limited to 'win/tclWinSock.c')
-rw-r--r--win/tclWinSock.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index 18afb01..63f166d 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -2431,22 +2431,18 @@ InitializeHostName(
Tcl_DStringInit(&ds);
if (TclpHasSockets(NULL) == TCL_OK) {
/*
- * Buffer length of 255 copied slavishly from previous version of
- * this routine. Presumably there's a more "correct" macro value
- * for a properly sized buffer for a gethostname() call.
- * Maintainers are welcome to supply it.
+ * The buffer size of 256 is recommended by the MSDN page that
+ * documents gethostname() as being always adequate.
*/
Tcl_DString inDs;
Tcl_DStringInit(&inDs);
- Tcl_DStringSetLength(&inDs, 255);
+ Tcl_DStringSetLength(&inDs, 256);
if (gethostname(Tcl_DStringValue(&inDs),
- Tcl_DStringLength(&inDs)) == 0) {
- Tcl_DStringSetLength(&ds, 0);
- } else {
- Tcl_ExternalToUtfDString(NULL,
- Tcl_DStringValue(&inDs), -1, &ds);
+ Tcl_DStringLength(&inDs)) == 0) {
+ Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&inDs), -1,
+ &ds);
}
Tcl_DStringFree(&inDs);
}