From e2a8d6ca464ae7a8fefa63c1e95c9387cfdbd339 Mon Sep 17 00:00:00 2001 From: dkf Date: Tue, 10 Jul 2012 11:03:23 +0000 Subject: * 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. --- ChangeLog | 7 +++++++ win/tclWinSock.c | 16 ++++++---------- 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 + + * 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 * 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); } -- cgit v0.12