patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Problem: Vim9: using job_status() on an unused var gives an error.
Solution: Return "fail". (closes #7158)
diff --git a/src/job.c b/src/job.c
index f55a8cd..5876c28 100644
--- a/src/job.c
+++ b/src/job.c
@@ -1894,12 +1894,21 @@
void
f_job_status(typval_T *argvars, typval_T *rettv)
{
- job_T *job = get_job_arg(&argvars[0]);
-
- if (job != NULL)
+ if (argvars[0].v_type == VAR_JOB && argvars[0].vval.v_job == NULL)
{
+ // A job that never started returns "fail".
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = vim_strsave((char_u *)job_status(job));
+ rettv->vval.v_string = vim_strsave((char_u *)"fail");
+ }
+ else
+ {
+ job_T *job = get_job_arg(&argvars[0]);
+
+ if (job != NULL)
+ {
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = vim_strsave((char_u *)job_status(job));
+ }
}
}