aboutsummaryrefslogtreecommitdiffstats
path: root/nnn.c
diff options
context:
space:
mode:
authorGravatar Vlad Glagolev <vaygr@users.noreply.github.com>2017-10-08 00:02:29 -0400
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-10-08 09:32:29 +0530
commitd835f72c6c285ae79dfad9a663852a8c2c82d030 (patch)
tree90614fd69dafe27eced2778d786557d2064a77d9 /nnn.c
parent8959a5b57dd75a0a0402fedd7a3705146631d419 (diff)
downloadnnn-d835f72c6c285ae79dfad9a663852a8c2c82d030.tar.gz
Fix segfault when SHLVL env var is not available (#52)
Diffstat (limited to 'nnn.c')
-rw-r--r--nnn.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/nnn.c b/nnn.c
index 450474d..2833589 100644
--- a/nnn.c
+++ b/nnn.c
@@ -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();
@@ -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 */