Skip to content

Commit

Permalink
Fix segfault when SHLVL env var is not available (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaygr authored and jarun committed Oct 8, 2017
1 parent 8959a5b commit d835f72
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ spawn(char *file, char *arg1, char *arg2, char *dir, uchar flag)
{
pid_t pid;
int status;
char *shlvl;

if (flag & F_NORMAL)
exitcurses();
Expand All @@ -568,10 +569,12 @@ spawn(char *file, char *arg1, char *arg2, char *dir, uchar flag)
if (dir != NULL)
status = chdir(dir);

shlvl = getenv("SHLVL");

/* Show a marker (to indicate nnn spawned shell) */
if (flag & F_MARKER) {
if (flag & F_MARKER && shlvl != NULL) {
printf("\n +-++-++-+\n | n n n |\n +-++-++-+\n\n");
printf("Spawned shell level: %d\n", atoi(getenv("SHLVL")) + 1);
printf("Spawned shell level: %d\n", atoi(shlvl) + 1);
}

/* Suppress stdout and stderr */
Expand Down

0 comments on commit d835f72

Please sign in to comment.