Skip to content

Commit

Permalink
confile_utils: convert to strnprintf()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 26, 2021
1 parent 18105e5 commit e6aeee8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lxc/confile_utils.c
Expand Up @@ -753,18 +753,17 @@ bool new_hwaddr(char *hwaddr)

seed = randseed(false);

ret = snprintf(hwaddr, 18, "00:16:3e:%02x:%02x:%02x", rand_r(&seed) % 255,
ret = strnprintf(hwaddr, 18, "00:16:3e:%02x:%02x:%02x", rand_r(&seed) % 255,
rand_r(&seed) % 255, rand_r(&seed) % 255);
#else

(void)randseed(true);

ret = snprintf(hwaddr, 18, "00:16:3e:%02x:%02x:%02x", rand() % 255,
ret = strnprintf(hwaddr, 18, "00:16:3e:%02x:%02x:%02x", rand() % 255,
rand() % 255, rand() % 255);
#endif
if (ret < 0 || ret >= 18) {
return log_error_errno(false, EIO, "Failed to call snprintf()");
}
if (ret < 0)
return log_error_errno(false, EIO, "Failed to call strnprintf()");

return true;
}
Expand Down

0 comments on commit e6aeee8

Please sign in to comment.