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)
commitfd5b9630b9a19d7acec452b7812d9b5d2edbaf42 (patch)
treeedee9c4b4d6e1b9a4b1de3b967b34b92e743b325 /win/tclWinSock.c
parent144e5850fb84e5be697789d2c35577a63f0b12dd (diff)
downloadtcl-fd5b9630b9a19d7acec452b7812d9b5d2edbaf42.zip
tcl-fd5b9630b9a19d7acec452b7812d9b5d2edbaf42.tar.gz
tcl-fd5b9630b9a19d7acec452b7812d9b5d2edbaf42.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);
}