-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Introduce banned.h for banned functions #325
Comments
You might consider using the gcc 'poison' pragma to detect uses of unwanted functions; you get a nicer error message from the compiler, I think:
Works with both gcc and clang (and if you care about more compilers than that you can always guard the #pragma with ifdef GNUC which both gcc and clang will satisfy). |
Hi @pm215 Yes indeed -- however, I do have to also consider a degree of portability. My understanding from reading about the |
The documentation doesn't say anything about #pragma being C99-only, and at least for gcc it still works fine with "-std=c89". (The _Pragma() syntax is C99-or-later, but not #pragma.) I'm surprised you still need to cater for pre-C99, though. I just tested with
and the codebase doesn't actually compile as C89/C90 at the moment, because (among other things) of files using "//" style comments, which are only valid in C99 or later. So (assuming nobody's complained that their compiler couldn't handle those) you might be reasonably able to just assume and require C99 :-) (I found the biggest portability issue to be the dependencies -- Ubuntu Focal LTS doesn't have a new enough libbson, for instance and I had to manually install the library from a later Ubuntu. If you have a system that has the dependencies it's probably also got a non-ancient gcc or clang.) |
Cool, then I'll use the pragma. Indeed, we've been using things like |
Well, I don't personally care whether the code base is strict C99-only. -std=gnu99, ie "C99 + GNU extensions" works. At least some of the problems with a -std=c99 compile seem to be in the system header files. |
It's the sort of thing we should address. If you don't want to do that, I understand. I was trying to drum up enough interest for someone other than myself to do this sort of work... |
Fvwm
has an old history, and as such the string handling has been organic, and has made use of the typical functions of the day, such asstrcat
andstrcpy
. Although theirn
counterparts (strncpy
,strncat
) are considered marginally safer, some effort should go in to converting these calls across the codebase.However, in doing this, it's probably only fair that some level of enforcement is achieved after this point so that there's no regressions. The
git
project has a concept ofbanned.h
which aborts compilation if defined functions are found. Something like this:Indeed, the following should be considered for banning:
... the above can all be replaced with
snprintf
, orstrlcpy
orasprintf
or any combination thereof.To undertake this work, use of
coccinelle
should be used to identify and rewrite the rules required.The text was updated successfully, but these errors were encountered: