The environment variable could contain format characters, causing
problems. Better to just use it directly.
int main(int argc, char *argv[])
{
- char hist_name[128];
+ char *hist_name;
struct sockaddr_un sun;
FILE *hist_fp = NULL;
int ch;
patterns = argv;
npatterns = argc;
- if (getenv("NSTAT_HISTORY"))
- snprintf(hist_name, sizeof(hist_name), getenv("NSTAT_HISTORY"));
- else
+ if ((hist_name = getenv("NSTAT_HISTORY")) == NULL) {
+ hist_name = malloc(128);
sprintf(hist_name, "/tmp/.nstat.u%d", getuid());
+ }
if (reset_history)
unlink(hist_name);