[PATCH] D16371: [compiler-rt/profile] Added Hostname to .profdata file
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 29 10:24:53 PST 2016
hfinkel added a comment.
In http://reviews.llvm.org/D16371#339419, @davidxl wrote:
> Windows has native API gethostname to get host name. I suggest define portability macro
>
> In InstrProfilingPort.h:
>
>
> #define COMPILER_RT_MAX_HOSTLEN 128
> #ifdef _MSC_VER
> #define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len)
> #else
> #define COMPILER_RT_GETHOSTNAME(Name, Len) GetHostName(Name, Len)
> #define COMPILER_RT_HAS_UNAME 1
> #endif
>
> in InstrProfilingFile.c
>
> #ifdef COMPILER_RT_HAS_UNAME
> int GetHostName(char *Name, int Len) {
>
> struct utsname N;
> int R;
> R = uname(&N);
> memcpy(Name, N.nodename, Len);
I think this needs to be strncpy, utsname.nodename is not guaranteed to be at least 128 characters. Also, we probably don't want to copy anything if the call to uname fails (so an early return would be better).
> return R;
>
> }
> #endif
>
> The rest of the code will be greatly simplified:
>
> char Name[COMPILER_RT_MAX_HOSTLEN];
>
> if (COMPILER_RT_GETHOSTNAME(Name, COMPILER_RT_MAX_HOSTLEN))
> return -1;
>
Otherwise, I agree.
http://reviews.llvm.org/D16371
More information about the llvm-commits
mailing list