summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--win/tclWinSock.c16
2 files changed, 13 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index dbf9e2e..1d3ba82 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-07-10 Donal K. Fellows <dkf@users.sf.net>
+
+ * 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.
+
2012-07-05 Don Porter <dgp@users.sourceforge.net>
* unix/tclUnixPipe.c: [Bug 1189293] Make "<<" binary safe.
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);
}