mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-11-28 00:25:43 +00:00
Add and use t_compare_errno.
Unfortunately, this causes a memory leak on FreeBSD due to localization: strerror_r() attempts to load localized error messages, fails, and creates a negative cache entry which is never freed.
This commit is contained in:
parent
c31fe69263
commit
8bc14dca97
3 changed files with 32 additions and 6 deletions
|
@ -103,6 +103,7 @@ int t_is_not_null(const void *);
|
|||
int t_compare_mem(const void *, const void *, size_t);
|
||||
int t_compare_str(const char *, const char *);
|
||||
int t_compare_strn(const char *, const char *, size_t);
|
||||
int t_compare_errno(int, int);
|
||||
#define t_compare_num(n, t) int t_compare_##n(t, t);
|
||||
t_compare_num(i, int);
|
||||
t_compare_num(u, unsigned int);
|
||||
|
|
|
@ -169,6 +169,32 @@ t_compare_strn(const char *expected, const char *received, size_t len)
|
|||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare to errno values, and print a verbose message if they differ.
|
||||
*/
|
||||
int
|
||||
t_compare_errno(int expected, int received)
|
||||
{
|
||||
char errbuf[256];
|
||||
|
||||
if (expected != received) {
|
||||
if (expected == 0) {
|
||||
t_printv("expected no errno\n");
|
||||
} else {
|
||||
strerror_r(expected, errbuf, sizeof errbuf);
|
||||
t_printv("expected errno: %s\n", strerror(expected));
|
||||
}
|
||||
if (received == 0) {
|
||||
t_printv("received no errno\n");
|
||||
} else {
|
||||
strerror_r(received, errbuf, sizeof errbuf);
|
||||
t_printv("received errno: %s\n", strerror(received));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare two numbers, and print a verbose message if they differ.
|
||||
*/
|
||||
|
|
|
@ -306,16 +306,15 @@ t_rfc3986(char **desc CRYB_UNUSED, void *arg)
|
|||
struct t_case *t = arg;
|
||||
char buf[256];
|
||||
size_t len;
|
||||
int ret;
|
||||
int fret, ret;
|
||||
|
||||
memset(buf, 0, sizeof buf);
|
||||
errno = 0;
|
||||
len = t->blen > sizeof buf ? sizeof buf : t->blen;
|
||||
ret = t_compare_i(t->ret,
|
||||
t->func(t->in, t->ilen, t->out ? buf : NULL, &len));
|
||||
fret = t->func(t->in, t->ilen, t->out ? buf : NULL, &len);
|
||||
ret = t_compare_i(t->ret, fret);
|
||||
if (fret != 0)
|
||||
ret &= t_compare_errno(t->err, errno);
|
||||
ret &= t_compare_sz(t->olen, len);
|
||||
if (t->ret != 0 || errno != 0)
|
||||
ret &= t_compare_i(t->err, errno);
|
||||
if (t->out)
|
||||
ret &= t_compare_strn(t->out, buf, t->blen - 1);
|
||||
return (ret);
|
||||
|
|
Loading…
Reference in a new issue