From 02d36fdab7415cd57dc09ca36f20e195977b7641 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Tue, 20 Mar 2018 13:29:29 -0500 Subject: [PATCH 1/2] execl: cast NULL sentinel to (char *), per man page and compiler warning From exec(3): > The list of arguments must be terminated by a null pointer, and, since these > are variadic functions, this pointer must be cast (char *) NULL --- src/libmain/shared.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 7d888202b..1445c8f03 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -263,7 +263,7 @@ void showManPage(const string & name) { restoreSignals(); setenv("MANPATH", settings.nixManDir.c_str(), 1); - execlp("man", "man", name.c_str(), NULL); + execlp("man", "man", name.c_str(), (char *)NULL); throw SysError(format("command 'man %1%' failed") % name.c_str()); } @@ -325,10 +325,10 @@ RunPager::RunPager() setenv("LESS", "FRSXMK", 1); restoreSignals(); if (pager) - execl("/bin/sh", "sh", "-c", pager, NULL); - execlp("pager", "pager", NULL); - execlp("less", "less", NULL); - execlp("more", "more", NULL); + execl("/bin/sh", "sh", "-c", pager, (char *)NULL); + execlp("pager", "pager", (char *)NULL); + execlp("less", "less", (char *)NULL); + execlp("more", "more", (char *)NULL); throw SysError(format("executing '%1%'") % pager); }); From f66ae2228880ba757af7dfcd216408ff95abaeba Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Wed, 21 Mar 2018 17:17:37 -0500 Subject: [PATCH 2/2] shared.cc: style: prefer "nullptr" over '(char *)NULL' --- src/libmain/shared.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 1445c8f03..91a4eaf92 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -263,7 +263,7 @@ void showManPage(const string & name) { restoreSignals(); setenv("MANPATH", settings.nixManDir.c_str(), 1); - execlp("man", "man", name.c_str(), (char *)NULL); + execlp("man", "man", name.c_str(), nullptr); throw SysError(format("command 'man %1%' failed") % name.c_str()); } @@ -325,10 +325,10 @@ RunPager::RunPager() setenv("LESS", "FRSXMK", 1); restoreSignals(); if (pager) - execl("/bin/sh", "sh", "-c", pager, (char *)NULL); - execlp("pager", "pager", (char *)NULL); - execlp("less", "less", (char *)NULL); - execlp("more", "more", (char *)NULL); + execl("/bin/sh", "sh", "-c", pager, nullptr); + execlp("pager", "pager", nullptr); + execlp("less", "less", nullptr); + execlp("more", "more", nullptr); throw SysError(format("executing '%1%'") % pager); });