-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In .c, open() with O_CREAT (or O_TMPFILE) requires the 3rd arg: mode #2512
Comments
ALE doesn't check your code, it runs external tools for checking your code. Maybe you could make this suggestion for one of the C linters that ALE runs. |
Great info, thank you! sample output: $ gcc -S -x c -iquote /home/user/sandbox/c/open_file_permission_ -std=c11 -Wall -D_FORTIFY_SOURCE=2 -O1 - < /tmp/c.c
<stdin>: In function ‘main’:
<stdin>:20:9: warning: unused variable ‘f’ [-Wunused-variable]
In file included from /usr/include/fcntl.h:328,
from <stdin>:5:
In function ‘open’,
inlined from ‘main’ at <stdin>:32:10:
/usr/include/bits/fcntl2.h:50:4: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
__open_missing_mode ();
^~~~~~~~~~~~~~~~~~~~~~
$ clang -S -x c -iquote /home/user/sandbox/c/open_file_permission_ -std=c11 -Wall -D_FORTIFY_SOURCE=2 -O1 - < /tmp/c.c
<stdin>:20:9: warning: unused variable 'f' [-Wunused-variable]
FILE *f=NULL;
^
1 warning generated. Should I look into preparing a PR? or is EDIT: However though, the above doesn't look good from within Ale(master), it's just a red marker on In file included from /usr/include/fcntl.h:328,
from <stdin>:5:
In function ‘open’,
inlined from ‘main’ at <stdin>:32:10:
/usr/include/bits/fcntl2.h:50:4: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
__open_missing_mode ();
At least the reason it doesn't work with #if __GNUC_PREREQ (4,3)
# define __warndecl(name, msg) \
extern void name (void) __attribute__((__warning__ (msg)))
# define __warnattr(msg) __attribute__((__warning__ (msg)))
# define __errordecl(name, msg) \
extern void name (void) __attribute__((__error__ (msg)))
#else
# define __warndecl(name, msg) extern void name (void)
# define __warnattr(msg)
# define __errordecl(name, msg) extern void name (void)
#endif So this is how it looks like thus far: diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim
index d965965d..875ea45d 100644
--- a/ale_linters/c/gcc.vim
+++ b/ale_linters/c/gcc.vim
@@ -2,14 +2,16 @@
" Description: gcc linter for c files
call ale#Set('c_gcc_executable', 'gcc')
-call ale#Set('c_gcc_options', '-std=c11 -Wall')
+call ale#Set('c_gcc_options', '-std=c11 -Wall -D_FORTIFY_SOURCE=2 -O1')
function! ale_linters#c#gcc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
- return '%e -S -x c -fsyntax-only'
+ " -fsyntax-only
+ " TODO: autoload/ale/handlers/gcc.vim
+ return '%e -S -x c -o /dev/null'
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(ale#Var(a:buffer, 'c_gcc_options')) . ' -' |
Are there any dangers in replacing I'll reopen this, as you might be on to something. |
We might be able to update ALE's error parser for C code to recognise the reference to inline code like so:
And then present that as an error in the list. Maybe we could look for lines like |
The only danger that I immediately thought of is if
sudo grub-mkconfig -o /dev/null that would remove /dev/null unless patched, it does it via mv -f ${grub_cfg}.new ${grub_cfg} (grub-mkconfig (GRUB) 2.02) |
I have updated the linters now to use |
I'll open another issue for parsing the inlined code errors. I believe Syntastic handles that, and we should too. |
Could Ale maybe warn or err, if it detects any use of
open()
(ie.man 2 open
) withO_CREAT
orO_TMPFILE
flags (ie. second argument) which doesn't also have a third argumentmode_t mode
which is required when using those flags.bad:
int fd=open("/path/somenewfile.log", O_WRONLY | O_CREAT | O_TRUNC | O_APPEND);
good:
int fd=open("/path/somenewfile.log", O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
The
bad
version won't show any errors or warnings, but you will get random mode flags set on that file after executing thatopen()
!I got bit by this (here), though it was my first time(iirc) using
open()
; but even so, it might be useful for others, me thinks.The text was updated successfully, but these errors were encountered: