Re: [PATCH v3 1/2] use HOST_NAME_MAX to size buffers for gethostname(2)
- Date: Tue, 18 Apr 2017 19:57:31 -0700
- From: Junio C Hamano <gitster@xxxxxxxxx>
- Subject: Re: [PATCH v3 1/2] use HOST_NAME_MAX to size buffers for gethostname(2)
Jonathan Nieder <jrnieder@xxxxxxxxx> writes:
>> @@ -274,7 +278,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
>> * running.
>> time(NULL) - st.st_mtime <= 12 * 3600 &&
>> - fscanf(fp, "%"SCNuMAX" %127c", &pid, locking_host) == 2 &&
>> + fscanf(fp, scan_fmt, &pid, locking_host) == 2 &&
> I hoped this could be simplified since HOST_NAME_MAX is a numeric literal,
> using the double-expansion trick:
> #define STR_(s) # s
> #define STR(s) STR_(s)
> fscanf(fp, "%" SCNuMAX " %" STR(HOST_NAME_MAX) "c",
> &pid, locking_host);
> Unfortunately, I don't think there's anything stopping a platform from
> #define HOST_NAME_MAX 0x100
> which would break that.
Yes, that was exactly why I went to the xstrfmt() route when I sent
mine yesterday ;-).
> So this run-time calculation appears to be necessary.
> Reviewed-by: Jonathan Nieder <jrnieder@xxxxxxxxx>