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

If we pass wrong arguments to printf (i.e forget a comma between 2 arguments), compiler can not check it out, and main function can not be parsed. #9

Open
zzdmfk opened this issue Aug 21, 2023 · 3 comments

Comments

@zzdmfk
Copy link

zzdmfk commented Aug 21, 2023

C code:
int printf(const char* str, ...);

struct dog
{
int a;
int b;
};

void set_dog(struct dog* d, int x)
{
d->b = x;
}

int main()
{
struct dog d;
set_dog(&d, 70);
//printf("hello world %i\r\n", d.b);
printf("hello world %i\r\n" d.b); //I forget a comma
return 0;
}

@zzdmfk zzdmfk changed the title When we passing wrong arguments to printf (i.e forget a comma between 2 arguments), compiler can not check it out, and main function can not be parsered. When we passing wrong arguments to printf (i.e forget a comma between 2 arguments), compiler can not check it out, and main function can not be parsed. Aug 21, 2023
@nibblebits
Copy link
Owner

Please provide the compiler output

@zzdmfk
Copy link
Author

zzdmfk commented Aug 22, 2023

Compiler outputs:
george@george-ubuntu:~/Desktop/gitcompiler/PeachCompiler$ ./main
section .data
section .text
extern printf
global set_dog
; set_dog function
set_dog:
push ebp
mov ebp, esp
push dword [ebp+12]
lea ebx, [ebp+8]
push ebx
pop ebx
mov ebx, [ebx]
add ebx, 4
push ebx
pop edx
pop eax
mov dword [edx], eax
pop ebp
ret
section .data
section .rodata
everything compiled file
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib32/Scrt1.o: in function _start': (.text+0x22): undefined reference to main'
collect2: error: ld returned 1 exit status
nasm -f elf32 ./test -o ./test.o && gcc -m32 ./test.o -o ./test

And I debugged it, found the function 'main' can not be parsed correctly in 'parse_function'.

@zzdmfk zzdmfk changed the title When we passing wrong arguments to printf (i.e forget a comma between 2 arguments), compiler can not check it out, and main function can not be parsed. If we pass wrong arguments to printf (i.e forget a comma between 2 arguments), compiler can not check it out, and main function can not be parsed. Aug 22, 2023
@nibblebits
Copy link
Owner

Thanks for reporting the problem

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

No branches or pull requests

2 participants