Skip to content

Commit

Permalink
Remove unnecessary checks from write_val.
Browse files Browse the repository at this point in the history
The *len variables are always at least 1, due to being calculated as
`strlen(fld)+1`. The fields are never NULL, instead we transmit empty
strings ("") on the wire.

Closes: #30 [via git-merge-pr]
  • Loading branch information
ericonr authored and the-maldridge committed Aug 24, 2021
1 parent 277aa72 commit 2301d30
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/write_val.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ int write_pwd(int fd, int swap, struct passwd *pwd)

if(full_write(fd, (char*)head, sizeof head) < 0) return -1;

if(namelen) if(full_write(fd, name_fld, namelen) < 0) return -1;
if(passwdlen) if(full_write(fd, passwd_fld, passwdlen) < 0) return -1;
if(gecoslen) if(full_write(fd, gecos_fld, gecoslen) < 0) return -1;
if(dirlen) if(full_write(fd, dir_fld, dirlen) < 0) return -1;
if(shelllen) if(full_write(fd, shell_fld, shelllen) < 0) return -1;
if(full_write(fd, name_fld, namelen) < 0) return -1;
if(full_write(fd, passwd_fld, passwdlen) < 0) return -1;
if(full_write(fd, gecos_fld, gecoslen) < 0) return -1;
if(full_write(fd, dir_fld, dirlen) < 0) return -1;
if(full_write(fd, shell_fld, shelllen) < 0) return -1;
return 0;
}

Expand Down Expand Up @@ -126,8 +126,8 @@ int write_grp(int fd, int swap, struct group *grp)
if(swap) swaplen = swap32(swaplen);
if(full_write(fd, (char*)&swaplen, sizeof(uint32_t)) < 0) return -1;
}
if(namelen) if(full_write(fd, name_fld, namelen) < 0) return -1;
if(passwdlen) if(full_write(fd, passwd_fld, passwdlen) < 0) return -1;
if(full_write(fd, name_fld, namelen) < 0) return -1;
if(full_write(fd, passwd_fld, passwdlen) < 0) return -1;
for(i = 0; grp->gr_mem[i]; i++) {
uint32_t len = strlen(grp->gr_mem[i]) + 1;
if(full_write(fd, grp->gr_mem[i], len) < 0) return -1;
Expand Down

0 comments on commit 2301d30

Please sign in to comment.