Browse Source

On success, fgets always terminates the result.

If fgets succeeds, then the resulting char array is always
terminated by a '\0'. No need to keep extra space, therefore
sizeof(buf) is the correct argument.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
master
Tobias Stoeckmann 9 years ago
parent
commit
35295f1902
  1. 2
      slstatus.c

2
slstatus.c

@ -447,7 +447,7 @@ run_command(const char *cmd)
warn("Failed to get command output for %s", cmd); warn("Failed to get command output for %s", cmd);
return smprintf("%s", UNKNOWN_STR); return smprintf("%s", UNKNOWN_STR);
} }
fgets(buf, sizeof(buf) - 1, fp); fgets(buf, sizeof(buf), fp);
pclose(fp); pclose(fp);
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';

Loading…
Cancel
Save