X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-gethostname.c;h=3ab0b86af53b7fb3f9b0a483a978539235145a2e;hb=9cedf3e1ac7dbdddefb7e172156e9000de7d80c2;hp=ef509530baf71bd4cc5bda6b483102097fe612be;hpb=655b30edb69df6cb28a431f2b340d0683b0b1f93;p=gnulib.git diff --git a/tests/test-gethostname.c b/tests/test-gethostname.c index ef509530b..3ab0b86af 100644 --- a/tests/test-gethostname.c +++ b/tests/test-gethostname.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Free Software Foundation + * Copyright (C) 2008, 2009 Free Software Foundation * Written by Simon Josefsson. * * This program is free software: you can redistribute it and/or modify @@ -17,7 +17,10 @@ #include +/* Get gethostname() declaration. */ #include +/* Get HOST_NAME_MAX definition. */ +#include #include #include @@ -28,9 +31,15 @@ int main (int argc, char *argv[]) { - char buf[2500]; + char buf[HOST_NAME_MAX]; int rc; + if (strlen (NOHOSTNAME) >= HOST_NAME_MAX) + { + printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX); + return 2; + } + strcpy (buf, NOHOSTNAME); rc = gethostname (buf, sizeof (buf));