Skip to content

Commit

Permalink
lib/: Use snprintf_() where appropriate
Browse files Browse the repository at this point in the history
And where we don't need snprintf_(), remove the cast to (void), since
using snprintf(3) and not one of its wrappers necessarily means that the
return value is ignored.

By this, I'm not claiming that those calls to snprintf(3) without error
handling are correct; it's just that I'm not sure, so I leave them alone.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Sep 6, 2023
1 parent 233370e commit cdba035
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/salt.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static /*@observer@*/void SHA_salt_rounds_to_buf (char *buf, unsigned long round
*/
assert (GENSALT_SETTING_SIZE > buf_begin + 17);

(void) snprintf (buf + buf_begin, 18, "rounds=%lu$", rounds);
snprintf(buf + buf_begin, 18, "rounds=%lu$", rounds);
}
#endif /* USE_SHA_CRYPT */

Expand Down Expand Up @@ -254,7 +254,7 @@ static /*@observer@*/void BCRYPT_salt_rounds_to_buf (char *buf, unsigned long ro
*/
assert (GENSALT_SETTING_SIZE > buf_begin + 3);

(void) snprintf (buf + buf_begin, 4, "%2.2lu$", rounds);
snprintf(buf + buf_begin, 4, "%2.2lu$", rounds);
}
#endif /* USE_BCRYPT */

Expand Down
13 changes: 4 additions & 9 deletions lib/subordinateio.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,30 +777,25 @@ gid_t sub_gid_find_free_range(gid_t min, gid_t max, unsigned long count)

static bool get_owner_id(const char *owner, enum subid_type id_type, char *id)
{
struct passwd *pw;
struct group *gr;
int ret = 0;
struct group *gr;
struct passwd *pw;

switch (id_type) {
case ID_TYPE_UID:
pw = getpwnam(owner);
if (pw == NULL) {
return false;
}
ret = snprintf(id, ID_SIZE, "%u", pw->pw_uid);
if (ret < 0 || ret >= ID_SIZE) {
if (snprintf_(id, ID_SIZE, "%u", pw->pw_uid) == -1)
return false;
}
break;
case ID_TYPE_GID:
gr = getgrnam(owner);
if (gr == NULL) {
return false;
}
ret = snprintf(id, ID_SIZE, "%u", gr->gr_gid);
if (ret < 0 || ret >= ID_SIZE) {
if (snprintf_(id, ID_SIZE, "%u", gr->gr_gid) == -1)
return false;
}
break;
default:
return false;
Expand Down

0 comments on commit cdba035

Please sign in to comment.