42School / norminette

Official 42 norminette
MIT License
926 stars 138 forks source link

Function types used as function prototypes get recognized as global variables. #478

Closed LordLorentz closed 7 months ago

LordLorentz commented 7 months ago

Describe the bug When a function type is used to prototype a function in a header, Norminette warns about it being a global variable, and returns an error about the function name not starting with g_.

Erroneous code

typedef void (t_decode)(char *, void *, size_t);

void justify_str(char *dst, void *in, t_decode *f, t_flags flags); t_decode decode_str; t_decode decode_dec; t_decode decode_dbl; t_decode decode_hexl; t_decode decode_hexu;

Norminette output

Notice: GLOBAL_VAR_DETECTED (line: 55, col: 1): Global variable present in file. Make sure it is a reasonable choice. Error: GLOBAL_VAR_NAMING (line: 55, col: 13): Global variable must start with g_ Notice: GLOBAL_VAR_DETECTED (line: 56, col: 1): Global variable present in file. Make sure it is a reasonable choice. Error: GLOBAL_VAR_NAMING (line: 56, col: 13): Global variable must start with g_ Notice: GLOBAL_VAR_DETECTED (line: 57, col: 1): Global variable present in file. Make sure it is a reasonable choice. Error: GLOBAL_VAR_NAMING (line: 57, col: 13): Global variable must start with g_ Notice: GLOBAL_VAR_DETECTED (line: 58, col: 1): Global variable present in file. Make sure it is a reasonable choice. Error: GLOBAL_VAR_NAMING (line: 58, col: 13): Global variable must start with g_ Notice: GLOBAL_VAR_DETECTED (line: 59, col: 1): Global variable present in file. Make sure it is a reasonable choice. Error: GLOBAL_VAR_NAMING (line: 59, col: 13): Global variable must start with g_

Additional infos

NiumXp commented 7 months ago

I'm not sure how we can fix it, because if we (do something like to) detect a global var when = is in declaration/definition, means that we will allow this:

int a;

int main(void)
{
   a = 1;

   return a;
}

We cannot consider if the type is int, unsigned int, etc. as a global var because what about user-defined types or a macro renaming int?

I think the only way to solve this problem is by checking the references for the variable name, but the norminette is currently unable to perform this type of analysis.

matthieu42Network commented 7 months ago

Hello, I think that this is too obscure to try to fix it.