Skip to content

Commit

Permalink
Pass pointer instead of value to writexa()
Browse files Browse the repository at this point in the history
Found by lgtm.com:

	This parameter of type xa_t is 88 bytes - consider passing a const pointer/reference instead.

Follow the suggestion and pass a pointer.
  • Loading branch information
rfjakob committed Jun 9, 2019
1 parent 505af7e commit 30882c7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cshatag.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ xa_t getstoredxa(FILE* f)
/**
* Write out metadata to file's extended attributes
*/
int writexa(FILE* f, xa_t xa)
int writexa(FILE* f, const xa_t* const xa)
{
int fd = fileno(f);
int flags = 0, err = 0;

char buf[100];
snprintf(buf, sizeof(buf), "%llu.%09lu", xa.s, xa.ns);
snprintf(buf, sizeof(buf), "%llu.%09lu", xa->s, xa->ns);
err = fsetxattr(fd, "user.shatag.ts", buf, strlen(buf), flags);
err |= fsetxattr(fd, "user.shatag.sha256", &xa.sha256, SHA256_NIBBLES, flags);
err |= fsetxattr(fd, "user.shatag.sha256", &xa->sha256, SHA256_NIBBLES, flags);

return err;
}
Expand Down Expand Up @@ -266,7 +266,7 @@ int main(int argc, const char* argv[])
needsupdate = 1;
}

if (needsupdate && writexa(f, a) != 0) {
if (needsupdate && writexa(f, &a) != 0) {
fprintf(stderr,
"Error: could not write extended attributes to file \"%s\": %s\n",
fn, strerror(errno));
Expand Down

0 comments on commit 30882c7

Please sign in to comment.