[LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
Cyril Hrubis
chrubis@suse.cz
Wed Oct 7 15:28:57 CEST 2015
Hi!
> +char *ltp_sock_addr(const struct sockaddr *sa, socklen_t salen)
> +{
> + char portstr[8];
> + static char str[128];
Also this is not thread safe and the testcases that use these fucntions
run in several threads. Even if the race condition where two threads
write to the str buffer at the same time is unlikely we should rather
change the interface to print the result into user supplied buffer.
So it reads:
char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen,
char *res, size_t res_len);
And the caller would just define array and pass it to the function as:
char buf[128];
...
tst_resm(..., tst_sock_addr(sa, salen, buf, sizeof(buf)), ...);
--
Cyril Hrubis
chrubis@suse.cz
More information about the Ltp
mailing list