Re: ✘Warnings on OSX

Fred Wright fw at fwright.net
Sat Aug 31 18:28:33 UTC 2019


On Sat, 31 Aug 2019, Matthew Selsky wrote:
> On Fri, Aug 30, 2019 at 08:01:59PM -0700, Fred Wright via devel wrote:
>>
>> On Thu, 29 Aug 2019, Gary E. Miller via devel wrote:
>>
>>> Warnings on OSX:
>>>
>>> [ 73/131] Compiling libntp/ntp_calendar.c
>>> ../../ntpd/ntp_control.c:2612:27: warning: format specifies type 'unsigned short' but the argument has type 'unsigned int' [-Wformat]
>>>                            socktoa(rmt_addr), (unsigned)SRCPORT(rmt_addr));
>>>                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> 1 warning generated.
>>>
>>>
>>> [106/131] Compiling ntpd/ntp_dns.c
>>> ../../ntpd/refclock_gpsd.c:2118:6: warning: implicit declaration of function 'strlcpy' is invalid in C99 [-Wimplicit-function-declaration]
>>>            strlcpy(pp->a_lastcode, tc, sizeof(pp->a_lastcode));
>>>            ^
>>> ../../ntpd/refclock_gpsd.c:2118:6: warning: this function declaration is not a prototype [-Wstrict-prototypes]
>>> 2 warnings generated.
>>>
>>> Anyone want to fix them?
>>
>> The second one, which was present on FreeBSD as well, seems to have been
>> caused by the definition of _XOPEN_SOURCE in refclock_gpsd.c.  And in spite
>> of what the comment says, this definition does *not* seem to be needed to
>> get strptime().  So simply removing it gets rid of the warning, and doesn't
>> break anything AFAICT.
>
> https://linux.die.net/man/3/strptime says:
>
> "This function is available since libc 4.6.8. Linux libc4 and libc5 
> includes define the prototype unconditionally; glibc2 includes provide a 
> prototype only when _XOPEN_SOURCE or _GNU_SOURCE are defined."
>
> Maybe that man page out of date?
>
> /usr/include/time.h on my Debian Stretch system (glibc 2.24) has:
>
> # ifdef __USE_XOPEN
> /* Parse S according to FORMAT and store binary time information in TP.
>   The return value is a pointer to the first unparsed character in S.  */
> extern char *strptime (const char *__restrict __s,
>                       const char *__restrict __fmt, struct tm *__tp)
>     __THROW;
> # endif
>
> _GNU_SOURCE implies _XOPEN_SOURCE...
>
> So we need _XOPEN_SOURCE set (or something that implies it) somewhere 
> upstream to get this prototype on newer glibc versions.

If it's necessary in some cases, it should be appropriately conditional, 
since it causes trouble in at least some cases as noted above.

It looks like refclock_gpsd is the only module that uses both strptime() 
and strlcpy().

Fred Wright


More information about the devel mailing list