mirror of
https://github.com/phillipberndt/autorandr
synced 2025-02-01 04:02:08 +00:00
Fix const warnings
gcc and clang report warnings due to -Wwrite-strings: $ docker run -it --rm -v "$PWD":/workspace -w /workspace gcc sh -c 'apt-get update && apt-get -y install libxcb1-dev libxcb-randr0-dev && make' (...) cc -pipe -o2 -Wstrict-overflow=5 -fstack-protector-all -W -Wall -Wextra -Wbad-function-cast -Wcast-align -Wcast-qual -Wconversion -Wfloat-equal -Wformat-y2k -Winit-self -Winline -Winvalid-pch -Wmissing-declarations -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wnormalized=nfc -Wold-style-definition -Woverlength-strings -Wpacked -Wpadded -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-compare -Wstack-protector -Wstrict-aliasing=2 -Wstrict-prototypes -Wundef -Wunsafe-loop-optimizations -Wvolatile-register-var -Wwrite-strings "-DAUTORANDR_PATH=\"\"" -o autorandr-launcher autorandr_launcher.c -lxcb -lxcb-randr autorandr_launcher.c: In function 'ar_launch': <command-line>: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] autorandr_launcher.c:47:41: note: in expansion of macro 'AUTORANDR_PATH' 47 | static char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL}; | ^~~~~~~~~~~~~~ autorandr_launcher.c:47:57: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 47 | static char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL}; | ^~~~~~~~~~ autorandr_launcher.c:47:69: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 47 | static char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL}; | ^~~~~~~~~~~ autorandr_launcher.c:47:82: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 47 | static char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL}; | ^~~~~~~~~
This commit is contained in:
parent
b573c4a63f
commit
303d00b31a
@ -42,10 +42,13 @@ __attribute__((format(printf, 1, 2))) static void ar_log(const char *format, ...
|
||||
|
||||
static int ar_launch(void)
|
||||
{
|
||||
static const char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL};
|
||||
char **comm = malloc(sizeof argv);
|
||||
memcpy(comm, argv, sizeof argv);
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
static char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL};
|
||||
if (execve(argv[0], argv, environ) == -1) {
|
||||
if (execve(argv[0], comm, environ) == -1) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, "Error executing file: %s\n", strerror(errsv));
|
||||
exit(errsv);
|
||||
@ -54,6 +57,7 @@ static int ar_launch(void)
|
||||
exit(127);
|
||||
} else {
|
||||
waitpid(pid, 0, 0);
|
||||
free(comm);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user