mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 02:55:06 -05:00
util: indicate truncated Unix socket path in UTI_SockaddrToString()
Specify the maximum length of the path in the snprintf() format to avoid a new gcc warning (-Wformat-truncation). If the path doesn't fit in the buffer, indicate with the '>' symbol that it was truncated. The function is used only for debug messages.
This commit is contained in:
@@ -4,10 +4,11 @@
|
||||
void test_unit(void) {
|
||||
NTP_int64 ntp_ts, ntp_fuzz;
|
||||
struct timespec ts, ts2;
|
||||
struct sockaddr_un sun;
|
||||
double x, y;
|
||||
Float f;
|
||||
int i, j, c;
|
||||
char buf[16];
|
||||
char buf[16], *s;
|
||||
|
||||
for (i = -31; i < 31; i++) {
|
||||
x = pow(2.0, i);
|
||||
@@ -145,4 +146,18 @@ void test_unit(void) {
|
||||
c++;
|
||||
}
|
||||
TEST_CHECK(c > 46000 && c < 48000);
|
||||
|
||||
for (i = 1; i < 2 * BUFFER_LENGTH; i++) {
|
||||
sun.sun_family = AF_UNIX;
|
||||
for (j = 0; j + 1 < i && j + 1 < sizeof (sun.sun_path); j++)
|
||||
sun.sun_path[j] = 'A' + j % 26;
|
||||
sun.sun_path[j] = '\0';
|
||||
s = UTI_SockaddrToString((struct sockaddr *)&sun);
|
||||
if (i <= BUFFER_LENGTH) {
|
||||
TEST_CHECK(!strcmp(s, sun.sun_path));
|
||||
} else {
|
||||
TEST_CHECK(!strncmp(s, sun.sun_path, BUFFER_LENGTH - 2));
|
||||
TEST_CHECK(s[BUFFER_LENGTH - 2] == '>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user