42School / norminette

Official 42 norminette
MIT License
926 stars 138 forks source link

gets stuck in an infinit loop when a function gets called without a ; #493

Open paulorsfaria opened 4 months ago

paulorsfaria commented 4 months ago

Describe the bug when the last function called has no ; in the end "example()" the norminette gets stuck on an infinite loop. This will only happen if there are no ; in the code following the function

Erroneous code like this it will get stuck in a lop

int example()
{
    get_cost()
    return 1
}

but if you add a ; after the return norm will work correctly

int example()
{
    get_cost()
    return 1;
}

Additional infos norminette 3.3.55

veliga-syutkin commented 3 months ago

+1

ErrorRaffyline0 commented 1 month ago

I found the same issue, however, it seems like the failure conditions are a little more complicated.

The loop only occurs when the last statement is a function without a semicolon. This is why, for example, Norminette does NOT execute a loop when you write statements such as return

int test(void)
{
    return (1)
}

but if you only write a function such as write without ;, Norminette DOES execute a loop.

#include <unistd.h>

int test(void)
{
    write(1, "42", 2)
}

If you write two or more subsequent functions without semicolons, Norminette won't get stuck in a loop, but instead unceremoniously crash with "Error: Unexpected EOF l.7" (Unexpected end of file at line 7).

#include <unistd.h>

int test(void)
{
    write(1, "Codam", 5)
    write(1, "42", 2)
}

This happens regardless of whether or not the functions are in the same statement body. Putting a semicolon ANYWHERE after a function without ; will prevent this behavior by terminating it. (You need more semicolons depending on the amount of erroneous functions you want to terminate, although for some weird reason it seems to terminate them all with one semicolon as long as you don't have an empty line at the end of the file.)

My best guess is that Norminette is hardcoded to process the file from top to bottom, and processes each line until she sees a semicolon. If she doesn't see one, she will loop if she doesn't encounter subsequent functions or semicolons, or she will process any function she sees afterward as if they were part of the offending line and then print lots of indentation, parenthesis, empty line, and other errors, or crash, depending on the syntax.

This would track with why she will complain about indentation here at line 7 and 12, and an empty line at line 10, because she is not aware that the statement body of loc was completed after the first function. (I end the file with a semicolon because otherwise Norminette would crash without useful error data.)

#include <unistd.h>

int loc(void)
{
    write(1, "Codam", 5)
}

int test(void)
{
    write(1, "42", 2)
}
;

I hope this was any help because I spent way more time on this than I am willing to admit and I should really get back to speedrunning C in the Piscine lol.

Additional infos Norminette 3.3.55 (According to French standards, Norminette's pronouns should be she/her unless otherwise specified)