Skip to content
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

Infinite loop if function call in a comment #58

Closed
huiman opened this issue Aug 28, 2023 · 8 comments · Fixed by #64
Closed

Infinite loop if function call in a comment #58

huiman opened this issue Aug 28, 2023 · 8 comments · Fixed by #64

Comments

@huiman
Copy link

huiman commented Aug 28, 2023

$ c_formatter_42 < file.c
$ python3 -m c_formatter_42 < file.c

not showing any output and freeze.

@cacharle
Copy link
Collaborator

cacharle commented Aug 28, 2023

what is the content of file.c?
what is the version of the package?
what is your version of Python?
what OS are you on?

@huiman
Copy link
Author

huiman commented Aug 28, 2023

I just found the cause of the problem.

this is my c:

#include "libft.h"

/*
The  bzero()  function  erases  the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area.

The explicit_bzero() function performs the same task as bzero().  It differs from bzero() in  that  it  guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "un‐necessary".
*/
void	bzero(void *s, size_t n)
{
                    unsigned char *ptr_s;     
}

I just found out that 42 does not allow the comment above function.

@cacharle
Copy link
Collaborator

Indeed, the comment is the issue, it's still a bug because it shouldn't hang like this.

if I remove the bzero() in the first line of the comment, it doesn't hang.

@cacharle cacharle changed the title c_formatter_42 freeze Infinite loop if function call in a comment Aug 28, 2023
@cacharle
Copy link
Collaborator

cacharle commented Aug 28, 2023

@keyhr, I see it hangs in the line_breaker function, do you have any idea why this behavior occurs?

(I don't think it needs to be correctly formatted but would be nice if it didn't hang)

❯ c_formatter_42 <t.c
^CTraceback (most recent call last):
  File "/usr/local/bin/c_formatter_42", line 33, in <module>
    sys.exit(load_entry_point('c-formatter-42', 'console_scripts', 'c_formatter_42')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/c_formatter_42/c_formatter_42/__main__.py", line 43, in main
    print(run_all(content), end="")
          ^^^^^^^^^^^^^^^^
  File "~/git/c_formatter_42/c_formatter_42/run.py", line 38, in run_all
    content = line_breaker(content)
              ^^^^^^^^^^^^^^^^^^^^^
  File "~/git/c_formatter_42/c_formatter_42/formatters/line_breaker.py", line 8, in line_breaker
    lines = [insert_break(line, column_limit) for line in lines]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/c_formatter_42/c_formatter_42/formatters/line_breaker.py", line 8, in <listcomp>
    lines = [insert_break(line, column_limit) for line in lines]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/c_formatter_42/c_formatter_42/formatters/line_breaker.py", line 22, in insert_break
    line_indent_level = indent_level(line)
                        ^^^^^^^^^^^^^^^^^^
  File "~/git/c_formatter_42/c_formatter_42/formatters/line_breaker.py", line 84, in indent_level
    if re.match(align_pattern, line):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/pythonXX/site-packages/re/__init__.py", line 166, in match
    return _compile(pattern, flags).match(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

@huiman
Copy link
Author

huiman commented Aug 28, 2023

I try update the comment and this format is working:
[delete second line and replace double spaces with single]

/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_bzero.c                                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: npattana <[email protected]>           +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2023/08/28 14:57:50 by hui               #+#    #+#             */
/*   Updated: 2023/08/28 18:12:26 by npattana         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"

/*
The function erases the data in the n bytes of the memory starting at the
location pointed to by s, by writing zeros (bytes containing '\0') to that area.
*/
void	bzero(void *s, size_t n)
{
	unsigned char	*ptr_s;
}

@younesaassila
Copy link
Contributor

Working on a fix...

@younesaassila younesaassila mentioned this issue Aug 31, 2023
@cacharle
Copy link
Collaborator

@huiman Can you test with the branch from #64 and tell us if it's fixed?

@huiman
Copy link
Author

huiman commented Sep 2, 2023

I have tested it, and the infinite loop that causes freezing is gone. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants