summaryrefslogtreecommitdiff
path: root/pathexec_env.c
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-10-12 22:41:01 -0400
committerJoe Crayne <joe@jerkface.net>2019-10-12 22:41:01 -0400
commitcdf1abf190f1097c4f6ae2ff0a9fa023df6982f1 (patch)
tree448e7823c18110750823a4bdd599af336983a314 /pathexec_env.c
parent695f7bb74e51cba61f3e1c035dd47ae68ac2964c (diff)
Applied debian patch to fix compiler warnings.
0014-fix-implicit-declarations-incompatible-types-argv-ty.patch From: Jan <cloux@rote.ch> Date: Sat, 2 Mar 2019 15:41:59 +0100 Subject: fix: implicit declarations, incompatible types, argv type MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Fixed a few compiler warnings: prot.c:13:7: warning: implicit declaration of function ‘setgroups’ [-Wimplicit-function-declaration] chpst.c:80:7: warning: implicit declaration of function ‘setgroups’; did you mean ‘getgroups’? [-Wimplicit-function-declaration] - added #include <grp.h>, see: https://linux.die.net/man/2/setgroups chkshsgr.c:11:19: warning: passing argument 2 of ‘getgroups’ from incompatible pointer type [-Wincompatible-pointer-types] - change 'short' to 'gid_t', see: https://linux.die.net/man/2/setgroups pathexec_run.c:18:5: warning: implicit declaration of function ‘execve’ [-Wimplicit-function-declaration] - add #include <unistd.h>, see: http://man7.org/linux/man-pages/man2/execve.2.html prot.c:17:10: warning: implicit declaration of function ‘setgid’; did you mean ‘getgrgid’? [-Wimplicit-function-declaration] - add #include <unistd.h>, see: https://linux.die.net/man/3/setgid seek_set.c:9:7: warning: implicit declaration of function ‘lseek’ [-Wimplicit-function-declaration] - add #include <unistd.h>, see: https://linux.die.net/man/2/lseek -------------------------------------- Fixed type of argv, from 'const char **argv' to 'char **argv' This resolves a lot of compiler typecast warnings like: pathexec_run.c:19:17: warning: passing argument 2 of ‘execve’ from incompatible pointer type [-Wincompatible-pointer-types] NOTE: this change might be disputable and not obvious at first. For arguments for argv as 'char **argv', see: The C Programming Language, Kernighan & Ritchie, Second Edition, Section 5.10, page 110 Command-line Arguments: main(int argc, char *argv[]) From https://riptutorial.com/c/example/3675/original--hello--world---in-k-r-c int main(int argc, char **argv) From C/C++ Kompendium (DE), Markt+Technik Verlag 2000, page 576, Chapter 12, main() Parameter: int main(int argc, char *argv[]) From http://www.cplusplus.com/articles/DEN36Up4/ int main(int argc, char* argv[]) // or char** argv From https://ece.uwaterloo.ca/~dwharder/icsrts/C/05/ int main( int argc, char *argv[] ) At https://stackoverflow.com/questions/5808679/why-is-main-argument-argv-of-type-char-rather-than-const-char is argued, that: - argv isn't const, since it's being created at runtime - in certain cases you should be able to rewrite argv from you program The main argument for this type change: the argv is used in a call to execve, so the type should be declared as compatible with execve parameters. http://man7.org/linux/man-pages/man2/execve.2.html defines: int execve(const char *filename, char *const argv[], char *const envp[]); so every argv defined as 'const char *const argv[]' was changed to: 'char *const argv[]'
Diffstat (limited to 'pathexec_env.c')
-rw-r--r--pathexec_env.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/pathexec_env.c b/pathexec_env.c
index 1305469..f873094 100644
--- a/pathexec_env.c
+++ b/pathexec_env.c
@@ -22,9 +22,9 @@ int pathexec_env(const char *s,const char *t)
22 return stralloc_cat(&plus,&tmp); 22 return stralloc_cat(&plus,&tmp);
23} 23}
24 24
25void pathexec_env_run(const char *file, const char *const *argv) 25void pathexec_env_run(const char *file, char *const *argv)
26{ 26{
27 const char **e; 27 char **e;
28 unsigned int elen; 28 unsigned int elen;
29 unsigned int i; 29 unsigned int i;
30 unsigned int j; 30 unsigned int j;
@@ -40,7 +40,7 @@ void pathexec_env_run(const char *file, const char *const *argv)
40 if (!plus.s[i]) 40 if (!plus.s[i])
41 ++elen; 41 ++elen;
42 42
43 e = (const char **) alloc((elen + 1) * sizeof(char *)); 43 e = (char **) alloc((elen + 1) * sizeof(char *));
44 if (!e) return; 44 if (!e) return;
45 45
46 elen = 0; 46 elen = 0;
@@ -68,7 +68,7 @@ void pathexec_env_run(const char *file, const char *const *argv)
68 alloc_free(e); 68 alloc_free(e);
69} 69}
70 70
71void pathexec(const char *const *argv) 71void pathexec(char *const *argv)
72{ 72{
73 return pathexec_env_run(*argv, argv); 73 return pathexec_env_run(*argv, argv);
74} 74}